Laravel 5记住我没有工作 [英] Laravel 5 remember me not working

查看:165
本文介绍了Laravel 5记住我没有工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得Laravel 记住我的功能.

我在User模型表中添加了记住标记"列. 我的User型号Authenticatable.用户模型不包含其他与记住我的功能"相关的特定内容

I added remember token column to my User Model table. My User Model Authenticatable. User model doesn't contain anything else specific related to remember me functionality

我正在使用默认的Auth驱动程序和防护.

I am using default Auth drivers and guard.

我的Usercontroller与默认值不同.它从Controller扩展.它不使用任何特征.在我的登录方法中,我使用Auth::login($userModelObject, true)登录用户.一切正常.记住我,令牌已在数据库中更新.我可以在浏览器XSRF-TOKENlaravel_sessionremember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d上看到3个cookie.

My Usercontroller is different from default one. It extends from Controller. It doesn't use any Traits. In my login method, I use Auth::login($userModelObject, true) to login user. Everything works fine. Remember me token gets updated in database. I can see 3 cookies on browser XSRF-TOKEN, laravel_session, remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d.

Auth::check()返回预期的true,但是如果我删除,过期或修改laravel_session,则在后续请求中,由于某些原因,remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d cookie也将被删除(我无法使用仅在我应用的中间件中),我认为这就是Laravel Auth驱动程序无法使用记住我的Cookie"来自动登录用户的原因.框架还自动应用CSRF中间件.

Auth::check() returns true as expected but if I either remove, expires, or modify laravel_session, in the subsequent request, remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d cookie also gets removed for some reason (I am not able to view it using var_dump($_COOKIE) in only middleware I applied) and I think that's why Laravel Auth driver isn't able to use remember me Cookie to autologin user. CSRF middleware is also being applied automatically by Framework.

什么可能导致此行为?我需要在用户模型或控制器上使用一些其他特征吗?

What could be causing this behaviour? Do I need to use some Additional Traits on my User Model or Controller?

注意:我使用的是Laravel 5.4,我的会话配置为:

Note: I am using Laravel 5.4 and my session config are:

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 20,
'expire_on_close' => false,
'encrypt' => false,
'files' => storage_path('framework/sessions'),
'connection' => null,
'table' => 'sessions',
'store' => null,
'lottery' => [2, 100],
'cookie' => 'laravel_session',
'path' => '/',
'domain' => env('SESSION_DOMAIN', null),
'secure' => env('SESSION_SECURE_COOKIE', false),
'http_only' => true

推荐答案

我发现了问题.我在Kernel.php中有这个\ Illuminate \ Session \ Middleware \ AuthenticateSession :: class.我将我的项目与新的laravel 5.4项目进行了比较,发现默认情况下已将其注释掉.我做到了,现在我的问题已解决.

I found the problem. I had this \Illuminate\Session\Middleware\AuthenticateSession::class in Kernel.php. I compared my project with new laravel 5.4 project and found that this is commented out by default. I did that and my problem is fixed now.

这篇关于Laravel 5记住我没有工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆