Skip to main content
POST
Sign In

Overview

The sign-in endpoint authenticates existing users and returns JWT access and refresh tokens. Users can authenticate using their email and password.

Endpoint

Request Body

string
required
User’s email address registered in the system.
string
required
User’s password.

Response

string
JWT access token for authenticating subsequent API requests. This is a short-lived token.
string
JWT refresh token used to obtain new access tokens when they expire.
object
Complete user object containing authenticated user’s information.
integer
Unique identifier for the user.
string
User’s username.
string
User’s email address.
string
User’s first name.
string
User’s last name.
string
User’s phone number.
string
URL to user’s avatar image (if uploaded).

Example Request

cURL
Python
JavaScript

Example Response

200 OK

Error Responses

400 Bad Request - Invalid Password
400 Bad Request - Missing Fields
404 Not Found - User Does Not Exist
500 Internal Server Error

Implementation Details

The sign-in endpoint is implemented in apps/users/views.py:21-44. Here’s the authentication flow:
  1. User Lookup: Retrieves user by email using get_object_or_404()
  2. Password Verification: Validates password using Django’s check_password() method
  3. Token Generation: Creates JWT tokens using RefreshToken.for_user(user)
  4. User Serialization: Returns complete user data via UsersSerializer
  5. Response: Returns tokens and user object on success

Code Reference

From apps/users/views.py:21-44:

Using the Access Token

Once you receive the access token, include it in the Authorization header for authenticated requests:
cURL
Python

Notes

  • This endpoint does not require authentication (@permission_classes([AllowAny]))
  • Authentication is performed using email (not username)
  • Passwords are never returned in the response
  • The access token has a limited lifetime and should be refreshed using the refresh token
  • Failed login attempts return specific error messages to help identify the issue