What I want to happen : Verify the user's email when clicking the button in the verification email.
What happens : The authentication is failing because laravel is not retrieving the bearer token of the user. It returns "Unauthenticated".
What I've done : Tested the verification in Postman and it's properly verifying the user, using the verification link sent in the email.
http://127.0.0.1:8000/verify/1/bd2c82278d7a76fc882d47348d0e981bfbcac894?expires=1678537895&signature=59ed9520ddd74820380afe47bd752d7be424ec89c485e035f8c6f72094f706e5
.
In postman, I included the bearer token in the Authorization tab. So the authentication of the email verification pushed through.
I have enabled MustVerifyEmail in my User model.
How do I pass through the bearer token so that laravel can access it when the link is clicked from the user email ?
My VerificationRequest
class VerificationRequest extends FormRequest
{
public function authorize(): bool
{
// $user = User::find($this->route('id'));
if (! hash_equals((string) $this->user()->getJWTIdentifier(), (string) $this->route('id'))) {
return false;
}
if (! hash_equals(sha1($this->user()->getEmailForVerification()), (string) $this->route('hash'))) {
return false;
}
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [];
}
public function fulfill() {
if (! $this->user()->hasVerifiedEmail()) {
$this->user()->markEmailAsVerified();
$this->user()->update([
'isVerified' => true
]);
event(new Verified($this->user()));
}
}
}
My Route
Route::get('/verify/{id}/{hash}', function(VerificationRequest $request) {
$request->fulfill();
return redirect('profile');
}) ->middleware(['auth', 'signed'])
->name('verification.verify');
The URL sent in the email
If you're having trouble clicking the "nyoom" button, copy and paste the URL below into your web browser: http://127.0.0.1:8000/verify/1/bd2c82278d7a76fc882d47348d0e981bfbcac894?expires=1678537895&signature=59ed9520ddd74820380afe47bd752d7be424ec89c485e035f8c6f72094f706e5