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)
| Field | Type | Description |
|---|---|---|
message | String | Status message indicating successful login |
data | Object | Contains user details and authentication token |
source | String | Source of the data (e.g., "db") |
Data Object Properties
| Field | Type | Description |
|---|---|---|
email | String | email 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 Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters or validation failed |
| 401 | Unauthorized - Invalid email or password |
| 403 | Forbidden - Account inactive or suspended |
| 404 | Not Found - Email address not registered |
| 500 | Internal 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
}