Skip to main content

Module auth

Module auth 

Source
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§

AuthWithBody
Marker for auth handlers with a body extractor as last arg.
Protected
An endpoint that requires authentication.

Traits§

AuthHandler
A handler that takes Auth as its first argument.
ProtectedEndpoint
Bind a handler to a Protected<Auth, E> endpoint.

Functions§

bind_protected