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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay