Skip to content

4. Profile

Abdullah bin Ammar edited this page May 20, 2025 · 1 revision

Routes Overview for profile.js

Note

These endpoints manage user account operations such as retrieving profile info, registration (in development only), and deleting accounts.

Method Endpoint Description
GET /profile Fetch the logged-in user’s profile.
POST /profile Create a new user account (disabled in production).
DELETE /profile Delete the logged-in user’s account.

Key Features

  • 👤 Profile Fetching: Retrieves authenticated user info with optional field and relation filters.
  • 🆕 Account Creation: Allows creating accounts in non-production environments using insertUserSchema.
  • Account Deletion: Allows users to delete their account and clears their session.
  • 🔐 Authentication Guard: GET and DELETE require authentication via isAuthenticated.
  • 🧪 Validation: Uses Zod schema to validate registration input in development.

Profile Management

Get Profile

GET /profile

Returns user profile data.

Query Parameters (optional):

  • fields[]: Array of user fields to retrieve
  • include[]: Related entities to include

Requires: Authentication

Response:

  • 200 OK with { user }
  • 401 Unauthorized if not logged in
  • 404 if user not found

Create Profile

POST /profile

Registers a new user. Only allowed in non-production environments.

Requires: No authentication
Body Schema: insertUserSchema

Response:

  • 201 Created with new user data
  • 400 Bad Request if validation fails
  • 403 Forbidden in production
  • 500 on server error

Delete Account

DELETE /profile

Deletes the currently logged-in user’s account and destroys the session if active.

Requires: Authentication

Response:

  • 200 OK with { success: true }
  • 401 Unauthorized if not logged in
  • 500 on error

Clone this wiki locally