Skip to content
Raiyan edited this page Jun 3, 2025 · 3 revisions

Auth Routes

Login User

GET /api/auth/login

Logs in a user using a Firebase ID token. If the user does not yet exist in the database, it returns newUser: true and the client should redirect to the signup flow.

Headers

Authorization: Bearer <FIREBASE_ID_TOKEN>

Behavior

  • Validates Firebase ID token.
  • If the user exists in the database, returns their information.
  • If the user does not exist, returns newUser: true.

Success Response (existing user)

{
  "success": true,
  "message": "User login successful",
  "data": {
    "newUser": false,
    "user": {
      "_id": "665be...",
      "uid": "55eO2tO...",
      "email": "raiyan@gmail.com",
      "displayName": "Raiyan",
      "avatar": "https://lh3.googleusercontent.com/...",
      "username": "raiyan123",
      "bio": "I love reading sci-fi and writing fiction.",
      "interestedGenres": ["sci-fi", "fantasy"],
      "createdAt": "2025-06-02T10:10:15.123Z",
      "updatedAt": "2025-06-02T10:10:15.123Z",
      "__v": 0
    }
  }
}

Success Response (new user)

{
  "success": true,
  "message": "User login successful",
  "data": {
    "newUser": true,
    "user": null
  }
}

Signup User

POST /api/auth/signup

Registers a new user with a unique username, bio, and list of interested genres. Must be called only if the login endpoint returns newUser: true.

Headers

Authorization: Bearer <FIREBASE_ID_TOKEN>
Content-Type: application/json

Request Body

req.body.data

{
  "username": "raiyan123",
  "bio": "I love reading sci-fi and writing fiction.",
  "interestedGenres": ["sci-fi", "fantasy"]
}

Behavior

  • Validates Firebase ID token.
  • Checks for an existing user.
  • If not found, creates a new user with additional fields from the request.

Success Response

{
  "success": true,
  "message": "User account created successfully",
  "data": {
    "user": {
      "_id": "665be7...",
      "uid": "55eO2t...",
      "email": "raiyan@gmail.com",
      "displayName": "Raiyan",
      "avatar": "https://lh3.googleusercontent.com/...",
      "username": "raiyan123",
      "bio": "I love reading sci-fi and writing fiction.",
      "interestedGenres": ["sci-fi", "fantasy"],
      "createdAt": "2025-06-02T10:10:15.123Z",
      "updatedAt": "2025-06-02T10:10:15.123Z",
      "__v": 0
    }
  }
}

Error Response (user already exists)

{
  "success": false,
  "message": "User already exists",
  "error": null
}

Clone this wiki locally