Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Adds Validated auth event #31357

Merged
merged 4 commits into from
Feb 5, 2020
Merged

[6.x] Adds Validated auth event #31357

merged 4 commits into from
Feb 5, 2020

Conversation

DarkGhostHunter
Copy link
Contributor

@DarkGhostHunter DarkGhostHunter commented Feb 5, 2020

This PR adds the Validated auth event. This event is fired after a User is retrieved from the User Provider and properly validated, but before the Login event and logic:

image

This allows any package to intercede on the authentication after a successful attempt but before login logic. As you can see, the Login event is fired after all login logic is already executed.

image

This allows to intercede into the authentication without having to retrieve the user two times. For example, we can now run complex logic and deny further authentication after the user is validated using a Listener:

public function handle(Validated $event)
{
    if ($event->user->isDynamicallyLocked()) {
        response()->view('auth.locked', ['user' => $event->user])->throwResponse();
    }
}

This is handy, for example, when we need to filter what Users can continue to authenticate depending on a complex prerequisites (like a relation value, or an external API response, whatever) which we cannot set in the LoginController, and without having to edit the SessionGuard or macro it.

Please comment so I don't feel alone. Thanks.

@taylorotwell taylorotwell merged commit 5aead14 into laravel:6.x Feb 5, 2020
@DarkGhostHunter
Copy link
Contributor Author

I'll comment myself. Good job.

@driesvints
Copy link
Member

@DarkGhostHunter thanks man 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants