Lavarel auth会议丢失了要求

发布于 2025-02-04 04:55:39 字数 1046 浏览 3 评论 0原文

我们尝试通过内置的身份验证功能手动对用户进行身份验证。

我们不保留数据库,因为目的不需要。

我们遵循了文档的这一部分: https:// https:// laravel。 com/docs/9.x/authentication#authenticate-a-user-Instance

我们通过某个请求使用户检查了auth :: check()方法,我得到了一个,所以它正在工作:

$user = User::make([
        'name' => $userGoogle->name,
        'email' => $userGoogle->email,
        'token' => $userGoogle->token,
        'refresh_token' => $userGoogle->refreshToken,
        'employeeId' => $employeeId,
    ]);

    Auth::login($user);
    //request()->session()->invalidate(); //Needed?
    //request()->session()->regenerateToken(); //Needed?

    dd(Auth::check());

但是,加载另一个测试页面时:

Route::get('test', function() {
    dd(Auth::check());
});

这总是返回false。我还尝试过再生会话令牌,因为我怀疑那里出现了问题。

但无济于事。它只是不起作用。还是强制性数据库?它在文档中没有说明,auth ::登录后的:: check()效果很好。

谢谢

We try to authenticate a user manually via the builtin Auth functionality.

We don't retain a database as that's not needed for our purpose.

We followed this part of the docs: https://laravel.com/docs/9.x/authentication#authenticate-a-user-instance

We make a user on a certain request, we checked the Auth::check() method and I get a true, so it's working:

$user = User::make([
        'name' => $userGoogle->name,
        'email' => $userGoogle->email,
        'token' => $userGoogle->token,
        'refresh_token' => $userGoogle->refreshToken,
        'employeeId' => $employeeId,
    ]);

    Auth::login($user);
    //request()->session()->invalidate(); //Needed?
    //request()->session()->regenerateToken(); //Needed?

    dd(Auth::check());

But, when loading another test page:

Route::get('test', function() {
    dd(Auth::check());
});

This always returns false. I also tried with regenerating the session token as I suspect something is going wrong there.

But no avail. It just doesn't work. Or is a database mandatory? It's not stated in the docs, and the ::check() after Auth::login works perfectly.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文