简体   繁体   English

Laravel 5.3记住我的Auth问题

[英]Laravel 5.3 Remember me Auth issue

I have implemented a remember me login in my laravel 5.3 project, but iam running with some issues, when the user return to the page its automaticaly logged in but the custom sessions variables are not set because the session already expired. 我已经在laravel 5.3项目中实现了一个记住我的登录,但是我运行了一些问题,当用户返回到页面时,它自动登录但是由于会话已经过期而没有设置自定义会话变量。

I have my sessions lifetime to 120 and expire on close is true. 我的会话生命周期为120,关闭时到期是真的。

My question is: how do I check if the user is being authed via remember me token to reasign session variables? 我的问题是:如何通过记住我的令牌来重新设置会话变量来检查用户是否正在被刷新? I was thinking to create a Middleware for that but i don't know if thats the correct approach. 我正在考虑为此创建一个中间件,但我不知道这是否是正确的方法。

My customs sessions variables are: 我的海关会话变量是:

session()->get('client_id') -> int
session()->get('acl') -> array

Can anyone guide me to the right direction? 谁能引导我走向正确的方向?

Check the following solution and see if it works. 检查以下解决方案,看看它是否有效。

Determine if the User Was Authenticated Via the Remember Cookie 通过记住Cookie确定用户是否经过身份验证

Edited: 编辑:

Add a event Listener to EventServiceProvider EventServiceProvider添加事件侦听器

 protected $listen = [
        'Illuminate\Auth\Events\Login' => [
            'App\Listeners\UpdateLoginType@handle',
        ],
    ];

Generate event and handler for the listener 为侦听器生成事件和处理程序

php artisan event:generate

Go To UpdateLoginType and edit handle method to check login type 转到UpdateLoginType并编辑handle方法以检查登录类型

 public function handle(Login $event)
    {
        if (\Auth::viaRemember()) {
            //do something
        } else {
            //do something else
        }
    }

Make sure your pass the remember variable properly while logging in. 确保在登录时正确传递remember变量。

Question similar to this one 问题与类似

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM