2

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.

Nikki
  • 336
  • 3
  • 13
  • I posted this as a bug in Laravel, but they closed it with no solution. https://github.com/laravel/framework/issues/26331 – Nikki Nov 14 '18 at 14:19
  • 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? – thecoolestguyever123 Nov 14 '18 at 14:19
  • 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 Nov 14 '18 at 14:25

2 Answers2

3

Via your issue from github. Simply change

$this->middleware('auth');

to

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

  • I also had to replace the verify() method from VerifiesEmails.php to get rid of the user ID check. – Nikki Nov 14 '18 at 14:41
0

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);
}
Nikki
  • 336
  • 3
  • 13