TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pvnm4/Social-Media-Backend/llms.txt
Use this file to discover all available pages before exploring further.
/login endpoint authenticates a registered user and returns a signed JWT access token. It follows the OAuth2 password flow: credentials are submitted as form-encoded data (not JSON), using FastAPI’s built-in OAuth2PasswordRequestForm. The returned access_token must be included in the Authorization: Bearer header for all protected routes.
Endpoint
Request
Content-Type:application/x-www-form-urlencoded
The request body must be form-encoded. Note that the field is named username per the OAuth2 specification, but it must contain the user’s email address — this is the value looked up against the email column in the users table.
The user’s email address (e.g.
user@example.com). Despite the OAuth2 field name username, this value is matched against the email column in the database.The user’s plaintext password. The API verifies this against the stored bcrypt hash. Always transmit over HTTPS in production.
Response
HTTP 200 OK The response body is a JSON object matching theToken schema (app/schemas.py):
The signed JWT bearer token to include in the
Authorization header of subsequent requests. The payload contains user_id (the authenticated user’s integer ID) and exp (the UTC expiry timestamp).Always
"bearer". Use this value literally when constructing the Authorization header.Error responses
| Status | Detail | Cause |
|---|---|---|
| 403 Forbidden | "Invalid Credentials" | No user exists with the supplied email, or the password does not match the stored bcrypt hash. |
"Invalid Credentials" message is returned for both a missing user and a wrong password — this is intentional to avoid leaking whether a given email address is registered.
Examples
Successful response example
Using the token
Pass theaccess_token value in the Authorization header as a Bearer token on every subsequent request that requires authentication:
get_current_user dependency (app/oauth2.py), which decodes the JWT, extracts the user_id claim, and fetches the corresponding user record from the database. If the token is missing, expired, or invalid, the server responds with 401 Unauthorized and the detail "Could not validate credentials".