tobischulz / vue-laravel-spa

A simple and clean starter-kit to start a new SPA project. Its like Jetstream without Inertia but with Vue-Router and Pinia as store.
42 stars 12 forks source link

401 on login #5

Closed daan3011 closed 1 year ago

daan3011 commented 2 years ago

I'm a complete newbie to vue so maybe this is a stupid question, sorry in advance. when I register a new account everything works fine but when I try to login with this account i get a 401 unauthorized response. After some testing I noticed that I get a 422 Unprocessable entity when I try to log in with credentials that actually return no matches. Thanks in advance

tobischulz commented 2 years ago

Hey,

do you have set the .env correct? Its very important that the SESSION_DOMAIN is the same you are using to serve your app. If this domain is not correct you cant login.

daan3011 commented 2 years ago

Thanks, I didn't setup the SESSION_DOMAIN. The request is posting now but I get a csrf token mismatch and when checking the console I saw that it's making infinite requests to /logout where I get a 419

edit: I also noticed that when I don't add the SESSION_DOMAIN newly registered users get saved in the database but after adding the session in .env they aren't saved

tobischulz commented 2 years ago

Try to add these variables to your .env and set it correctly:

SESSION_SECURE_COOKIE=false
SESSION_DOMAIN=laravel-vue-spa-boilerplate.test 

SESSION_SECURE_COOKIE only when you serve your app with https. SESSION_DOMAIN has to be the same as your domain/APP_NAME (without protocol)

Maybe the previously created cookie does that. Please clear the cache and remove all cookies from the spa page. After clearing the cache and removing all cookies for this page you should be able to login. If not, try inkognito tab or another browser.

tobischulz commented 2 years ago

PS: the infinite loop has been fixed. https://github.com/tobischulz/laravel-vue-spa-boilerplate/commit/b69947a43ef06387ee1ae9911b7fea81d9cb5ed8

daan3011 commented 2 years ago

Cool, thanks for the help. I managed to get it working