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

feat: ✨ route guards #43

Merged
merged 1 commit into from
Oct 11, 2024
Merged

feat: ✨ route guards #43

merged 1 commit into from
Oct 11, 2024

Conversation

lucas-labs
Copy link
Owner

@lucas-labs lucas-labs commented Oct 11, 2024

Alternate solution to #10 that doesn't require an implementation of route-controller level middlewares.

This implementation doesn't use starlette middlewares, but... it works.

  • Implements controller/route level route guards.
class AuthGuard(Guard):
    def can_activate(self, request: Request, *, context: Any, set_result: GuardCb) -> bool:
        # guard logic
  • Per-Controller guards.
@controller('/secure')
@use_guard(AuthGuard)
class Controller:
    ...
  • Per-Route Controller.
@controller('/secure')
class Controller:
    @get('/')
    @use_guard(AuthGuard)
    def annotated(self, user: Annotated[User, GuardExtra]) -> dict:
        ...

Note

Doesn't implement application-level route guards; it would be more efficient
to implement this when we have controller/route-level middlewares (see #6)

Although not ideal, this is a temp solution

@lucas-labs lucas-labs merged commit aea2a3b into master Oct 11, 2024
7 checks passed
@lucas-labs lucas-labs deleted the feat/route-guards branch October 11, 2024 06:31
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.

1 participant