Skip to content

require_authenticated

require_authenticated() — builds a guard that allows the request iff request.state.user is set by an upstream authentication guard.

Signature

def require_authenticated() -> type:
    ...

It is a factory like the other guards — call it:

@use_guards(bearer_token(verify=...), require_authenticated())
@controller("/billing")
class BillingController: ...

Behaviour

  • request.state.user is an AuthUser → allow (True).
  • No AuthUser on state → UnauthorizedError (401). Authentication is required; the missing piece is the user's identity, not their permissions.

When to use it

Use it when a handler needs somebody authenticated, but you don't care about specific roles or scopes:

from lauren import controller, get, use_guards
from lauren_guards import require_authenticated

@use_guards(require_authenticated())
@controller("/account")
class AccountController:
    @get("/settings")
    async def settings(self) -> dict:
        return {"prefs": {}}

Layering

require_authenticated() is typically redundant next to an authentication guard that already raises 401 when no credential is present — it shines when combined with guards that might skip authentication for some routes (e.g. @public routes).