Best way to modify Auth in Laravel 5.5

Published 4 days ago by mdk999

I ran make:auth and now have an authentication/login system. I'm looking to modify this but wanted some input on the best way to accomplish this. Do I modify the login controller? do I make my own, include traits the override the functions (ie getLogin). Hoping to add things like redirect based on user role, email confirmation, login with phone number, etc. Thanks much.

Best Answer (As Selected By mdk999)
martinbean

@mdk999 Override the methods provided by the trait where necessary.

redirect based on user role

Do this in a method called authenticated(), which receives the Request instance and the newly-created User instance. You can redirect based on the role there:

public function authenticated(Request $request, $user)
{
    switch ($user->role) {
        //
    }
}

email confirmation

You can either do this in your RegisterController in a registered() method, or attach a listener to the built-it Illuminate\Auth\Events\Registered event that sends the email confirmation.

login with phone number

You’ll need to create a new route and controller action to handle this. Not sure how this would work in practice though. Is it literally, enter a phone number to log in? What happens if I find another user’s phone number? I can then just log in as them?

martinbean

@mdk999 Override the methods provided by the trait where necessary.

redirect based on user role

Do this in a method called authenticated(), which receives the Request instance and the newly-created User instance. You can redirect based on the role there:

public function authenticated(Request $request, $user)
{
    switch ($user->role) {
        //
    }
}

email confirmation

You can either do this in your RegisterController in a registered() method, or attach a listener to the built-it Illuminate\Auth\Events\Registered event that sends the email confirmation.

login with phone number

You’ll need to create a new route and controller action to handle this. Not sure how this would work in practice though. Is it literally, enter a phone number to log in? What happens if I find another user’s phone number? I can then just log in as them?

mdk999

Thanks for the quick reply. It was helpful and appreciated.

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