require_authenticated¶
require_authenticated() — builds a guard that allows the request iff request.state.user is set by an upstream authentication guard.
Signature¶
It is a factory like the other guards — call it:
@use_guards(bearer_token(verify=...), require_authenticated())
@controller("/billing")
class BillingController: ...
Behaviour¶
request.state.useris anAuthUser→ allow (True).- No
AuthUseron 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).
Related¶
- require_roles — gate by named roles.
- require_scopes — gate by OAuth scopes.