User activation

Published 2 years ago by spoon

Hello.

I have a strange problem that I can't solve.

When a user is registered, I redirect them to a feed url, open a modal and tell my user to activate his account by clicking the email link that I sent them. But after I click the link, I keep being redirected to the exact same page (feed) and my account isn't being activated. What could be the problem here?

routes.php

Route::group(['namespace' => 'Auth'], function ()
{
    Route::group(['middleware' => 'auth'], function ()
    {
        Route::get('activate/{token}', 'PasswordController@activate');
    });
});

PasswordController

public function activate($token) {
    //get token value.
    // find the user that belongs to that token.
    $activation = User::where("confirmation_code", $token)->get()->first();
    $activation->confirmed = 1;
    $activation->save();
}

RedirectIfAuthenticated.php If I remove feed url, it works. But I don't want to do that.

public function handle($request, Closure $next)
{
    if ($this->auth->check()) {

        return redirect('/feed');
    }

    return $next($request);
}
Snapey
Snapey
2 years ago (929,715 XP)

Your token validation is protected by auth middleware. This means the potential user would need to be logged in before they could access the token function.

Just move it outside the middleware block?

Please sign in or create an account to participate in this conversation.