User authenticating but not staying logged in Laravel 5.3 - php

My Stack:
Laravel Version: 5.3.9
PHP Version: 7.0.8
Database Driver & Version: MySQL Ver 14.14 Distrib 5.7.15
Redis
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#email.com', '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:
Login from the /login path
I am redirected to the correct page upon successful login
I try and navigate to another page
I am redirected back to login

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.

Related

Website is unable to properly retrieve session information after PHP update

I had some very simple code on a website to handle logins on the root of the site using ion_auth:
if(!$this->ion_auth->logged_in())
{
redirect("/login");
}
That page posts to /auth/login, which is handled by ion_auth. If the login is successful, the user is redirected to the root of the site. Otherwise, they go back to /login to try again. I initially thought I'd forgotten the password, but with a series of var_dump() calls, I found that the login is successful, but the call to $this->ion_auth->logged_in() returns false anyway.
All of this is after the host upgraded to PHP 7 - the code worked before. I've tried upgrading ion_auth, but it didn't help.
There were session related problems in early CI 3.x version, documented here and here
several session related issues were resolved in the latest versions, see the change logs
solution: update to CI 3.1.7. (latest version as writing)
Upgrading From a Previous Version

Laravel 5.4 Keeps Logging user out

After anytime I move between pages or reload the same page it logs the user out. It worked fine in 5.2 but when I upgraded to 5.4 this problem appeared. I don't know what to provide because I just used:
php artisan make:Auth
and made my front end the way I wanted it. It is connected to my database remotely and it works because if I put in bad information it does not work. When it logs me in it redirects me, I see my
{{Auth:check()}}
working fine because I see new links that weren't there when I wasn't logged in. However, anytime I move between any of my pages my naviagation bar goes back to if the user wasn't logged in. It seems as if it is not carrying the session information between pages.

Can't keep user logged in after upgrading to Laravel 5.4

I had an application made with Laravel 5.3 that was running fine, but after upgrading to Laravel 5.4, every time we authenticate, it goes fine and we have access to user informations :
{"id":X,"name":"Foo","email":"foo#bar.com", . . .}
The thing is, it is not really logged in as when we want to access a protected view that this user would have access to, it redirects on the login page.
I checked a fresh install of Laravel 5.4 methods of authentication and can't find any difference between application and this fresh 5.4 application.
So if someone could tell me where this problem comes from, it would be really helpful,
Thanks.
EDIT : It seems that the Auth()->user() gets null value while in the middleware that protects the routes.
I found what went wrong, but didn't wrote the answer here.
What was actually happening is that it seemed that session cookies had the encrypt config option set to false, but it was needing the EncryptCookies middleware, which was missing.

Laravel - login page redirecting back to homepage, but only on production

I can access my login page using the URL on my homepage - /login, and login to the site as expected. However, in production, if I click the link to login, it "processes" and then redirects back to the homepage.
<li>
Login
</li>
I have the logs set to daily within my application, however, nothing is 'erroring'.
How can I debug this in production? I'm using Laravel Forge. Why would the standard /auth/login URL not work in production, but on local?
I've just pushed my latest build to prod, so they're both using the exact same code base. I have also cleared all configs/caches on php artisan.
If you require further code/information, please just let me know.
Many thanks.
Clear your browser cache/cookies and try again.
Check for any server configurations differences between production and development.
Are you 100% sure that both environment has identical code?

symfony2 login not working FOSUSerBundle

Help! I don't know why, but recently I can no longer log into my Symfony2 website. When I try to login, I simply get redirected back to the login page with no error, and no indication of what is wrong. I've cleared my apc cache, my prod and dev caches, and I've been able to reproduce the error in both dev and prod. I've set g+wrx and u+rwx recursively.
How do I debug a login page when no exception is being thrown? The error occurs in multiple browsers on multiple machines.
It turns out I had a de-sync between the form_login check_path in my security.yml and the root of my FOSUserBundle routing information. Because the two didn't sync up, clicks on the login page would simply result in a page redirect rather than passing it to the login classes.

Categories