-
Notifications
You must be signed in to change notification settings - Fork 136
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
feature: Add guard assignment helper middleware #362
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #362 +/- ##
=========================================
Coverage 98.97% 98.97%
Complexity 289 289
=========================================
Files 20 20
Lines 783 783
=========================================
Hits 775 775
Misses 8 8
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
Co-authored-by: Rita Zerrizuela <[email protected]>
|
||
$this->get($routeUnspecifiedGuard) | ||
->assertStatus(Response::HTTP_OK) | ||
->assertSee($defaultGuardClass); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this assertion done above? On L43.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies if this is intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Widcket 👋 No worries! It's repeated a few times to ensure the guard changes are properly persisted between requests. Here's the breakdown of what it's doing:
// Ensure the active guard is the default/unspecified one, 'web' ($defaultGuardClass' value.)
$this->get($routeUnspecifiedGuard)
->assertStatus(Response::HTTP_OK)
->assertSee($defaultGuardClass);
// Attempt to change the active guard to one that doesn't exist; throws an error.
$this->get($routeNonexistentGuard)
->assertStatus(Response::HTTP_INTERNAL_SERVER_ERROR);
// Change the guard to 'testGuard' ($sdkGuardClass' value.)
$this->get($routeMiddlewareAssignedGuard)
->assertStatus(Response::HTTP_OK)
->assertSee($sdkGuardClass);
// Ensure the active guard was correctly persisted as `testGuard` following the previous request.
$this->get($routeUnspecifiedGuard)
->assertStatus(Response::HTTP_OK)
->assertSee($sdkGuardClass);
// Clear the active guard we specified, resetting it to the app's default, `web`.
$this->get($routeMiddlewareUnassignedGuard)
->assertStatus(Response::HTTP_OK)
->assertSee($defaultGuardClass);
// Ensure the active guard was correctly persisted as `web` following the previous request.
$this->get($routeUnspecifiedGuard)
->assertStatus(Response::HTTP_OK)
->assertSee($defaultGuardClass);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification!
Changes
This PR adds a convenience helper middleware that simplifies the assignment of specific guards for handling request routing.
Example usage:
This ensures that the example guard,
someGuardName
, is used to handle the routing of requests for the specified group of routes.This streamlines our documentation by ensuring that downstream applications are configured to use the Auth0 Laravel SDK guard, regardless of other installed guards or configurations.
References
N/A
Testing
This PR adds tests to cover the new middleware.
Contributor Checklist