由于用户未通过身份验证,Laravel 无法验证电子邮件

时间:2021-03-16 15:29:06

标签: php laravel

TLDR;我使用 Valet 和 mailhog 进行电子邮件测试。这只是基本的注册表单。即使在注册路径中,用户也不会被验证,他们在创建用户实例后立即登录。

在 POST /register 控制器中

Auth::login($user= User::create([...])); <-- here we login the user right after the user created.
event(new Registered($user));

然后,当用户点击验证电子邮件时,发生了这种情况:

Route::get('email/verify/{id}/{hash}',function (EmailVerificationRequest $request) {
 // user is not authenticated, thus redirected again to login route.
 // this happened again and again when we click the link from email verification,
// even though we are "logged in" in the session
})->middleware(['auth','signed',...]);

有人可以帮忙吗?这是 Laravel 版本:8.32.1 & PHP 版本:8.0.0 谢谢

1 个答案:

答案 0 :(得分:0)

当您尝试对用户进行身份验证时,您是否确定它实际上是在创建用户?在尝试登录之前,您应该检查 null。一旦您能够验证记录是否已创建和存储,您才应该尝试登录。

相关问题