Lavarel auth会议丢失了要求
我们尝试通过内置的身份验证功能手动对用户进行身份验证。
我们不保留数据库,因为目的不需要。
我们遵循了文档的这一部分: 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论