Laravel Auth::login() doesn't persist after ch

2019-08-28 22:28发布

previously before i change the domian in session.php,my Auth::login() is working fine and it will persist the cookie so they dont need to login again. When some of my friend told me that when they click login (from facebook), it will somehow return InvalidStateException in AbstractProvider.php.

I google around knew there maybe some issue cause by the cookie, and the solution is changing the domain in the session.php from null to my domain (example myapps.com).

After i've change to the myapps.com, invalidstateException no longer occurs but it wont persist my login. After a 6 - 12 hours, it required me to login again.

Below is my code ( i believe my code is correct just after i've change the session and the login wont persist anymore).

$UserLogin = User::where('facebook_id', '=', $user->getId())->first();
Auth::login($UserLogin, true);

1条回答
趁早两清
2楼-- · 2019-08-28 23:18

The core problem is that your browser stores two cookies from multiple domains with the same cookie name called laravel_session; when you make a request, both cookies with the same name are sent to the server.

In your config/session.php:

//change this
'cookie' => 'laravel_session'

//and this
'domain' => 'my_domain'

By changing the name of the cookie and domain, you'll get around the problem by the storing new cookies under a new name.

查看更多
登录 后发表回答