DEV Community

Alejandro Reyes
Alejandro Reyes

Posted on

Help please, Problem with Logout

Hi, I'm new using Laravel, I'm developing an application with laravel and react, but when I try to logout a session, console shows this:

Config.jsx:11
POST http://localhost:8000/api/v1/auth/logout 401 (Unauthorized)
:8000/perfiltitular:1 Uncaught (in promise)
AxiosError {message: 'Request failed with status code 401', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
code
:
"ERR_BAD_REQUEST"
config
:
{transitional: {…}, adapter: Array(2), transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
message
:
"Request failed with status code 401"
name
:
"AxiosError"
request
:
XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: true, upload: XMLHttpRequestUpload, …}
response
:
{data: {…}, status: 401, statusText: 'Unauthorized', headers: AxiosHeaders, config: {…}, …}
stack
:
"AxiosError: Request failed with status code 401\n at settle (http://[::1]:5173/node_modules/.vite/deps/axios.js?v=7c27b233:1203:12)\n at XMLHttpRequest.onloadend (http://[::1]:5173/node_modules/.vite/deps/axios.js?v=7c27b233:1420:7)\n at Axios.request (http://[::1]:5173/node_modules/.vite/deps/axios.js?v=7c27b233:1780:41)"
[[Prototype]]
:
Error

Could someone help me please? This is my getLogout in Config.jsx
getLogout:()=>axios.post(${base_api_url}/auth/logout)

And here It's my route in api.php
Route::group(['middleware' => 'auth:sanctum'], function () {

    //::auth
    Route::post('/auth/logout', [AuthController::class, 'logout']);
Enter fullscreen mode Exit fullscreen mode

Top comments (0)