Authentication
User authentication operations
Creates a new user account. Admin registration requires whitelisted email.
User's email address
User's password
User role (optional for registration)
User registered successfully. Sets refreshToken cookie.
Invalid input data provided. See errors object for details.
Admin registration denied for non-whitelisted email.
An unexpected error occurred on the server.
POST /api/v1/auth/register HTTP/1.1
Host: blog-api.codewithsadee.com
Content-Type: application/json
Accept: */*
Content-Length: 59
{
"email": "[email protected]",
"password": "text",
"role": "admin"
}
{
"accessToken": "text",
"user": {
"_id": "text",
"username": "text",
"email": "[email protected]",
"role": "user",
"firstName": "text",
"lastName": "text",
"socialLinks": {
"website": "text",
"facebook": "text",
"instagram": "text",
"linkedin": "text",
"x": "text",
"youtube": "text"
},
"createdAt": "2025-09-14T23:44:07.808Z",
"updatedAt": "2025-09-14T23:44:07.808Z"
}
}
Authenticates a user and returns tokens.
User's email address
User's password
User role (optional for registration)
Login successful. Sets refreshToken cookie.
Invalid input data provided. See errors object for details.
The specified resource was not found.
An unexpected error occurred on the server.
POST /api/v1/auth/login HTTP/1.1
Host: blog-api.codewithsadee.com
Content-Type: application/json
Accept: */*
Content-Length: 59
{
"email": "[email protected]",
"password": "text",
"role": "admin"
}
{
"accessToken": "text",
"user": {
"_id": "text",
"username": "text",
"email": "[email protected]",
"role": "user",
"firstName": "text",
"lastName": "text",
"socialLinks": {
"website": "text",
"facebook": "text",
"instagram": "text",
"linkedin": "text",
"x": "text",
"youtube": "text"
},
"createdAt": "2025-09-14T23:44:07.808Z",
"updatedAt": "2025-09-14T23:44:07.808Z"
}
}
Generates a new access token using the refresh token cookie.
HTTP-only refresh token cookie.
Access token refreshed successfully.
Invalid input data provided. See errors object for details.
Authentication information is missing or invalid (e.g., missing/expired token).
An unexpected error occurred on the server.
POST /api/v1/auth/refresh-token HTTP/1.1
Host: blog-api.codewithsadee.com
Accept: */*
{
"accessToken": "text"
}
Invalidates the refresh token and clears the cookie. Requires both access and refresh tokens.
HTTP-only refresh token cookie.
Logout successful. Clears refreshToken cookie.
Invalid input data provided. See errors object for details.
Authentication information is missing or invalid (e.g., missing/expired token).
An unexpected error occurred on the server.
POST /api/v1/auth/logout HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*
{
"message": "Logged out successfully"
}
Was this helpful?