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] Add "unauthenticated" method in auth middleware #30177

Merged
merged 3 commits into from
Oct 4, 2019
Merged

[6.x] Add "unauthenticated" method in auth middleware #30177

merged 3 commits into from
Oct 4, 2019

Conversation

TitasGailius
Copy link
Contributor

It would be nice to have an easy way to customise the "unauthenticated" behaviour in Authenticate middleware.

For example, I'd like to display a 404 page when the user is unauthenticated.

Of course, one solution might be to catch AuthenticationException in the exception handler and adjust the behaviour accordingly but I find it much cleaner to do it in the middleware.

With this PR I could simply override the unauthenticated method in the Authenticate middleware that ships with Laravel.

class Authenticate extends Middleware
{
    /**
     * Handle unauthenticated user.
     *
     * @return void
     *
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
     */
    protected function unauthenticated()
    {
        throw new NotFoundHttpException;
    }
}

*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function unauthenticated($request, array $gaurds)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in method parameter $gaurds

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function unauthenticated($request, array $gaurds)
protected function unauthenticated($request, array $guards)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow sorry, I don't know how I missed that. thanks!

@taylorotwell taylorotwell merged commit 2095b02 into laravel:6.x Oct 4, 2019
i-bajrai pushed a commit to i-bajrai/framework that referenced this pull request Oct 4, 2019
* Separate "unauthenticated" method in auth middleware

* Update Authenticate.php

* Update Authenticate.php
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.

4 participants