Expand description
Type-level authentication for endpoints.
Protected<Auth, E> wraps an endpoint type to declare that it requires
authentication. The compiler enforces that the handler’s first argument
is the auth extractor type.
§Example
ⓘ
use typeway_server::auth::Protected;
// Tag endpoints as protected in the API type
type API = (
GetEndpoint<TagsPath, TagsResponse>, // public
Protected<AuthUser, GetEndpoint<UserPath, UserResponse>>, // auth required
);
// Handlers for protected endpoints MUST accept AuthUser as first arg.
async fn get_user(auth: AuthUser, state: State<Db>) -> Json<User> { ... }
// Wire up with bind_auth!():
Server::<API>::new((
bind!(get_tags), // public
bind_auth!(get_user), // protected — AuthUser enforced
));Structs§
- Auth
With Body - Marker for auth handlers with a body extractor as last arg.
- Protected
- An endpoint that requires authentication.
Traits§
- Auth
Handler - A handler that takes
Authas its first argument. - Protected
Endpoint - Bind a handler to a
Protected<Auth, E>endpoint.