Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.4 - Disable auto login after registration

I need to disable auto login after register an user in laravel 5.4 application. There are enough sources [example] for 5.2 and 5.3 version but it is hard find out a solution for 5.4 version.

In Laravel 5.4 there is no AuthController as it divided to LoginController and RegisterController. Guide me to disable auto login in laravel 5.4.

like image 607
Shashika Avatar asked Apr 05 '17 08:04

Shashika


2 Answers

Since your RegisterController uses RegistersUsers trait, all of the trait's methods are available to RegisterController. The method you need to override, in order to prevent users to be logged in after they successfully registered is register(). Here's the initial body of the method:

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

The line: $this->guard()->login($user); is where the user gets logged in. You can either remove it or modify it to suit your needs.

like image 168
Ivanka Todorova Avatar answered Sep 25 '22 18:09

Ivanka Todorova


If you use default register route you can do it like this...

in RegistersUsers.php file

comment this line in register function

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

I hope this helps you!!

like image 43
Akbar Mirsiddikov Avatar answered Sep 24 '22 18:09

Akbar Mirsiddikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!