2
votes

Laravel Version: 5.7.10 PHP Version: 7.2.10 Database Driver & Version: MySql 8.0.11

I am having new users verify their email address before I send them first time login credentials. They receive the verification email, and verification works. However, the page that they are supposed to be redirected to afterwards does not appear. The home page appears instead. Next time they log in, they are taken the the post-verification page. There is no auth middleware set on the route, and I can reach the post-verification page just fine when not logged in.

I set the redirect page in VerificationController with protected $redirectTo = '/verified'. And this is working, just not until the user logs in.

2
I posted this as a bug in Laravel, but they closed it with no solution. github.com/laravel/framework/issues/26331Nikki Aaron
Is there middleware specified inside of the controller? In your thing you have $this->middleware('auth'); shouldn't this be $this->middleware('auth')->except('verify'); For your use case?Chad
Yes, it should, thank you! I had checked at the route middleware in Kernel.php, but did not notice more middleware in the controller.Nikki Aaron

2 Answers

3
votes

Via your issue from github. Simply change

$this->middleware('auth');

to

$this->middleware('auth')->except('verify');

0
votes

Change middleware as commented by luminoslty, and also change VerifiesEmail.php from

public function verify(Request $request)
{
    if ($request->route('id') == $request->user()->getKey() &&
        $request->user()->markEmailAsVerified()) {
        event(new Verified($request->user()));
    }

    return redirect($this->redirectPath())->with('verified', true);
}

to

public function verify(Request $request)
{
    $user = User::find($request->route('id'));
    if ($user) {
        $user->markEmailAsVerified()) {
        event(new Verified($user));
    }

    return redirect($this->redirectPath())->with('verified', true);
}