dericcain
dericcain

Reputation: 2290

User authenticating but not staying logged in Laravel 5.3

My Stack:

I am using the Laravel auth:make scaffolding and when I login I am redirected to the correct page, but when I try to navigate to another page, I am redirected to login. I take a look at the debugbar and for the web routes auth, it says that I am logged in as a guest.

I created a route at /test-login that has this code:

Auth::attempt(['email' => '[email protected]', 'password' => 'password']);

and I am logged in until I go to another page. For some reason, the session doesn't seem to be persisting for authentication. However, it appears that tokens are persisting in the session.

I tried installing a fresh copy of Laravel and moving all of the files that I edited over to that install and it still doesn't work, so it must be something in one of my files, I just can'y figure out what. I also uninstalled predis/predis because that was around the time I noticed some issues - no luck. For the session, I now have it using file instead of Redis. Any ideas?

Steps To Reproduce:

  1. Login from the /login path
  2. I am redirected to the correct page upon successful login
  3. I try and navigate to another page
  4. I am redirected back to login

Upvotes: 0

Views: 352

Answers (1)

dericcain
dericcain

Reputation: 2290

I finally found it... Dumb mistake on my part. For the logout link in my nav partial, I had

{{ Auth::logout() }}

Which logged me out since every page included the nav partial. Well... it happened and I spent too much time looking for it too.

Upvotes: 3

Related Questions