Skip to content

Allow passing multiple gaurds to the auth middleware #3685

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

Merged
merged 1 commit into from
Mar 21, 2016

Conversation

JosephSilber
Copy link
Contributor

Using this, you'd be able to allow access to a single route for multiple guards:

Route::get('foo', 'Foo@foo')->middleware('auth:web,api');

@taylorotwell
Copy link
Member

I think the check might should be changed to if (! $this->authenticated()) because the guest method reads weird how it returns false, etc.

@taylorotwell
Copy link
Member

Thoughts?

@JosephSilber
Copy link
Contributor Author

@taylorotwell updated.

return response('Unauthorized.', 401);
} else {
return redirect()->guest('login');
if ($this->check($guards)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks weird to put success condition before failed condition, in Middleware.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not weird at all. You just maybe haven't seen it be done that way.

I actually like it quite a bit. It decreases the level of indentation, which is always a good thing.

@taylorotwell
Copy link
Member

Would anyone ever want this to be an "and" check instead of an "or" check?

@JosephSilber
Copy link
Contributor Author

For an "and" check, you can just run the middleware twice:

->middleware('auth|auth:api');

@shehi
Copy link

shehi commented Mar 18, 2016

Make it OR please. Not every JSON request is an AJAX request.

@shehi
Copy link

shehi commented Mar 18, 2016

And why "allow" has become synonymous with "make it mandatory"?! Why $guards parameter is mandatory? Make it $guards = [] maybe?

taylorotwell added a commit that referenced this pull request Mar 21, 2016
Allow passing multiple gaurds to the auth middleware
@taylorotwell taylorotwell merged commit 4f4d378 into laravel:develop Mar 21, 2016
@taylorotwell
Copy link
Member

$guards isn't mandatory.

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