Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
463 views
in Technique[技术] by (71.8m points)

fortify - I have an error with logout in the stack laravel 8 / jetstream / inertiajs

I'm trying to set a logout route.

I found a lot of blade syntax (like that) but none with vuejs. So I tried to replicate the result of the blade syntax by inserting an input with the csrf token in value and the name set to "_token". (the csrf variable contains the string located in the XSRF-TOKEN cookie).

When I post, I have this error in console: POST http: // localhost: 3000 / logout 419 (unknown status)

Can you tell me where my mistake is? How can I logout properly and be redirected to the page of my choice?

<form method="POST" :action="$route('logout')">
   <input type="hidden" name="_token" :value="csrf">
   <button type="submit">Logout</button>
</form>
question from:https://stackoverflow.com/questions/65617308/i-have-an-error-with-logout-in-the-stack-laravel-8-jetstream-inertiajs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found the solution.

My error was on the recovery of the csrf token which was not good. I would retrieve the long string contained in the XSRF-TOKEN cookie, while I had to receive the token from my backend. These 2 strings are strictly different, for some reason that I don't know yet.

I just needed to send the csrf token to my front-end with the csrf_token() method

return Inertia::render('Dashboard', [
   'publications' => $publications,
   'users' => $users,
   'csrf_token' => csrf_token()
]);

I didn't need to do the form manually either

Finally, I was able to grab the token as a prop and include it in my post request like this:

this.$inertia.post('/logout', {
    _token: this.$props.csrf_token
})

This link helped me


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...