How to disable auto login after registration of a new user in laravel?

Asked 7 years ago Modified 21 hours ago 13067 Views
0
Anonymous Post Date: Apr 09, 2019

Answers (1)

1

Disabling auto login after registration of a new user is very important in Laravel if you are securing the auth routes using middleware which means you can't register a user without logging in.

If you don't disable auto login function, you are going to get logged in as a new user every time you register a new user which is annoying.

So, have a look on how to disable auto login after registration of a new user in Laravel.

Your RegisterController method uses RegisterUsers trait which is added right above the method as shown below.

use Illuminate\Foundation\Auth\RegistersUsers;

Open this file which is located inside vendor\laravel\framework\src\Illuminate\Foundation\Auth directory.

Search for the method register which looks as shown below.

public function register(Request $request)
{
    $this->validator($request->all())->validate();

    event(new Registered($user = $this->create($request->all())));

    $this->guard()->login($user);

    return $this->registered($request, $user)
      ?: redirect($this->redirectPath());
}

$this->guard()->login($user) is the piece of code that makes the new user log in after registration.

Either remove this piece of code or modify it as per your requirement to prevent the new user log in after registration.

Jiwan Thapa Answered: Apr 08, 2019
Comments

Sign in to help the community by answering this question.

Log In to Answer