Nikki
Nikki

Reputation: 416

Laravel 5.7 - How can I show email verification redirect page when the user is not logged in?

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.

Upvotes: 2

Views: 3350

Answers (2)

Nikki
Nikki

Reputation: 416

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);
}

Upvotes: 0

thecoolestguyever123
thecoolestguyever123

Reputation: 983

Via your issue from github. Simply change

$this->middleware('auth');

to

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

Upvotes: 3

Related Questions