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

Conversation

@TitasGailius
Copy link
Contributor

TitasGailius commented Oct 3, 2019

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)

This comment has been minimized.

Copy link
@palokankare

palokankare Oct 4, 2019

Typo in method parameter $gaurds

This comment has been minimized.

Copy link
@m1guelpf

m1guelpf Oct 4, 2019

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

This comment has been minimized.

Copy link
@TitasGailius

TitasGailius Oct 4, 2019

Author Contributor

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

TitasGailius and others added 2 commits Oct 4, 2019
@taylorotwell taylorotwell merged commit 2095b02 into laravel:6.x Oct 4, 2019
1 check passed
1 check passed
continuous-integration/styleci/pr The analysis has passed
Details
i-bajrai added 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
Projects
None yet
4 participants
You can’t perform that action at this time.