馃摌
Blog API
  • Documentation
  • API References
  • Root
  • Authentication
  • Users
  • Blogs
  • Likes
  • Comments
  • Models
Powered by GitBook

漏 2025 codewithsadee

On this page

Was this helpful?

Export as PDF

Authentication

PreviousRootNextUsers

Was this helpful?

User authentication operations

Refresh Access Token

post

Generates a new access token using the refresh token cookie.

cookie
refreshTokenstring 路 jwtRequired

HTTP-only refresh token cookie.

Responses
200
Access token refreshed successfully.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
500
An unexpected error occurred on the server.
application/json
post
POST /api/v1/auth/refresh-token HTTP/1.1
Host: blog-api.codewithsadee.com
Accept: */*
{
  "accessToken": "text"
}

Logout User

post

Invalidates the refresh token and clears the cookie. Requires both access and refresh tokens.

Authorizations
cookie
refreshTokenstring 路 jwtRequired

HTTP-only refresh token cookie.

Responses
200
Logout successful. Clears refreshToken cookie.
application/json
400
Invalid input data provided. See errors object for details.
application/json
401
Authentication information is missing or invalid (e.g., missing/expired token).
application/json
500
An unexpected error occurred on the server.
application/json
post
POST /api/v1/auth/logout HTTP/1.1
Host: blog-api.codewithsadee.com
Authorization: Bearer JWT
Accept: */*
{
  "message": "Logged out successfully"
}
  • POSTRegister New User
  • POSTLogin User
  • POSTRefresh Access Token
  • POSTLogout User

Register New User

post

Creates a new user account. Admin registration requires whitelisted email.

Body
emailstring 路 email 路 max: 50Required

User's email address

passwordstring 路 min: 8Write-onlyRequired

User's password

rolestring 路 enumOptional

User role (optional for registration)

Possible values:
Responses
201
User registered successfully. Sets refreshToken cookie.
application/json
Responseall of
400
Invalid input data provided. See errors object for details.
application/json
403
Admin registration denied for non-whitelisted email.
application/json
500
An unexpected error occurred on the server.
application/json
post
POST /api/v1/auth/register HTTP/1.1
Host: blog-api.codewithsadee.com
Content-Type: application/json
Accept: */*
Content-Length: 59

{
  "email": "name@gmail.com",
  "password": "text",
  "role": "admin"
}
{
  "accessToken": "text",
  "user": {
    "_id": "text",
    "username": "text",
    "email": "name@gmail.com",
    "role": "user",
    "firstName": "text",
    "lastName": "text",
    "socialLinks": {
      "website": "text",
      "facebook": "text",
      "instagram": "text",
      "linkedin": "text",
      "x": "text",
      "youtube": "text"
    },
    "createdAt": "2025-06-07T21:02:00.942Z",
    "updatedAt": "2025-06-07T21:02:00.942Z"
  }
}

Login User

post

Authenticates a user and returns tokens.

Body
emailstring 路 email 路 max: 50Required

User's email address

passwordstring 路 min: 8Write-onlyRequired

User's password

rolestring 路 enumOptional

User role (optional for registration)

Possible values:
Responses
200
Login successful. Sets refreshToken cookie.
application/json
Responseall of
400
Invalid input data provided. See errors object for details.
application/json
404
The specified resource was not found.
application/json
500
An unexpected error occurred on the server.
application/json
post
POST /api/v1/auth/login HTTP/1.1
Host: blog-api.codewithsadee.com
Content-Type: application/json
Accept: */*
Content-Length: 59

{
  "email": "name@gmail.com",
  "password": "text",
  "role": "admin"
}
{
  "accessToken": "text",
  "user": {
    "_id": "text",
    "username": "text",
    "email": "name@gmail.com",
    "role": "user",
    "firstName": "text",
    "lastName": "text",
    "socialLinks": {
      "website": "text",
      "facebook": "text",
      "instagram": "text",
      "linkedin": "text",
      "x": "text",
      "youtube": "text"
    },
    "createdAt": "2025-06-07T21:02:00.942Z",
    "updatedAt": "2025-06-07T21:02:00.942Z"
  }
}