Skip to main content

Version: v1

Logout User

Terminates a user's session by clearing the HTTP-only refresh token cookie. Upon successful logout, the user will need to re-authenticate to access the protected routes.


HTTP Method & Endpoint

GET | /auth/logout


Response Format

Success Response (200 OK)

FieldTypeDescription
messageStringStatus message indicating successful login
dataObjectContains user details and authentication token
sourceStringSource of the data (e.g., "db")

Data Object Properties

FieldTypeDescription
emailStringemail id of the user

Sample Success Response

{
"message": "Logout Success",
"data": {
"email": "abc@gmail.com"
},
"source": ""
}
important

Don't forget to remove the customerId from local storage during logout to avoid stale or unauthorized access.

Examples

JavaScript (React)

import axios from "axios";
import { api } from "../constant";

const logoutUser = async () => {
try {
const response = await api.get("/auth/logout");

//removing customerId and cartId on logout
localStorage.removeItem("customerId");
localStorage.removeItem("cartId");

console.log("Logout successful:", response.data);
} catch (error) {
console.error("Logout failed:", error.response?.data || error.message);
}
};

The cartId is stored during the creation of cart .

Error Responses

Status CodeDescription
400Bad Request - Invalid parameters or validation failed
401Unauthorized - Invalid email or password
403Forbidden - Account inactive or suspended
404Not Found - Email address not registered
500Internal Server Error - Something went wrong on the server

Sample Error Responses

Invalid Credentials:

{
"requestId": "8d472d95-140e-414d-bbd7-26f0b82bd059",
"error": "UnauthorizedException",
"statusCode": 401,
"message": "Unauthorized",
"path": "/auth/logout",
"timestamp": 1748353090215
}