Internal Documentation internal
TalkIDE internal documentation

Invalidate the refresh token server-side for the authenticated user. Requires a valid JWT access token. Frontend removes both tokens from localStorage.

  • The access token is validated via the Authorization: Bearer header.
  • The refresh token is passed in the request body and is deleted from the database.
  • After logout the user must log in again to obtain new tokens.
  • If the refresh token is not found (already logged out), the server still returns 200 OK — the operation is idempotent from the user’s perspective.
sequenceDiagram
    actor User

    User->>+FE: clicks Logout

    FE->>+BE: POST /api/v1/auth/logout <br> Authorization: Bearer {accessToken} <br> LogoutRequest

    BE->>BE: validate JWT access token
    alt access token invalid or missing
        BE-->>FE: 401 Unauthorized <br> ErrorResponse
    end

    BE->>BE: validate request body
    alt request is invalid
        BE-->>FE: 400 Bad Request <br> ErrorResponse
    end

    BE->>DB: delete refresh token record (if exists)

    BE->>-FE: 204 No Content

    FE->>FE: remove accessToken and refreshToken from localStorage
    FE->>-User: redirect to login screen

POST /api/v1/auth/logout LogoutRequest:

{
  "refreshToken": "*****"
}

204 No Content (success, no body)

400 Bad Request (validation) ErrorResponse:

{
  "status": 400,
  "code": "VALIDATION_ERROR",
  "message": "Validation failed",
  "errors": [
    { "field": "refreshToken", "message": "must not be blank" }
  ]
}

401 Unauthorized (missing or invalid access token) ErrorResponse:

{
  "status": 401,
  "code": "AUTHENTICATION_FAILED",
  "message": "Access token is missing or invalid"
}

Frontend

Validations

FieldConstraintsSizePatternNote
refreshTokennot_blankread from localStorage by the FE

Backend

Validations

FieldConstraintsSizePatternNote
refreshTokennot_blank

Test Cases

GIVENWHENTHEN
authenticated user with valid tokenslogout is called204 No Content, refresh token deleted from DB
refresh token not found in DBlogout is called204 No Content (idempotent)
no Authorization headerlogout is called401 AUTHENTICATION_FAILED error response is returned
expired access tokenlogout is called401 AUTHENTICATION_FAILED error response is returned
refreshToken field is blanklogout is called400 VALIDATION_ERROR error response is returned
invalid request (empty body)logout is called400 VALIDATION_ERROR error response is returned

Was this page helpful?

Thanks for the feedback.