tobischulz/vue-laravel-spa

401 on login

Closed this issue · 5 comments

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

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.

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

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.

PS: the infinite loop has been fixed. b69947a

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