0

I am trying to set up a double authentication page under laravel, for that I add a checkTotp method that verifies that the user has activate double authentication and redirect this user to the page in question.

The problem is that I am not redirected and the code continues to execute.

public function login(Request $request)
{
    $this->validateLogin($request);
    ...
    $this->checkTotp($request);
    dd('after');
    ...
}

protected function checkTotp(Request $request) 
{
    $user = User::where('email', $request->get('email'))->first();
    if (!is_null($user->totp_key)) {
        $request->session()->put('user_id', $user->id);
        return redirect('login/totp');
    }
}

What happens is that I enter the checkTotp method but the redirect does not work. My output is the dd('after'). I don't understand why I am not redirected. Can someone help me?

Quentin

1 Answers1

0

The checkTotp function returns a redirect, but you want the login function to return that redirect, such that it is passed to the browser. You might want to move the redirect to the main function and let checkTOTP just return true/false.

public function login(Request $request)
{
    $this->validateLogin($request);
    ...
    if ($this->checkTotp($request)) return redirect('login/totp');
    dd('after');
    ...
}

protected function checkTotp(Request $request) 
{
    $user = User::where('email', $request->get('email'))->first();
    if (!is_null($user->totp_key)) {
        $request->session()->put('user_id', $user->id);
        return true;
    }
    return false;
}
rrr
  • 412
  • 4
  • 10