-
Notifications
You must be signed in to change notification settings - Fork 1
Auth
Raiyan edited this page Jun 3, 2025
·
3 revisions
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.
Authorization: Bearer <FIREBASE_ID_TOKEN>
- Validates Firebase ID token.
- If the user exists in the database, returns their information.
- If the user does not exist, returns
newUser: true.
{
"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": true,
"message": "User login successful",
"data": {
"newUser": true,
"user": null
}
}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.
Authorization: Bearer <FIREBASE_ID_TOKEN>
Content-Type: application/json
req.body.data
{
"username": "raiyan123",
"bio": "I love reading sci-fi and writing fiction.",
"interestedGenres": ["sci-fi", "fantasy"]
}- Validates Firebase ID token.
- Checks for an existing user.
- If not found, creates a new user with additional fields from the request.
{
"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
}
}
}{
"success": false,
"message": "User already exists",
"error": null
}