diff --git a/readme.md b/readme.md index 0767a1f..3060d0c 100644 --- a/readme.md +++ b/readme.md @@ -127,6 +127,54 @@ let app = Router::new() })); ``` +A more wholistic example: + +```rs +use crate::{ + auth, + service::{hello, MyUserData}, +}; +use axum::{ + middleware, + routing::{get, post}, + Json, Router, +}; + +use chrono::{Duration, Utc}; + + +pub fn create_router() -> Router { + let user_data = MyUserData; + let jwt_secret = "secret"; + + let app = Router::new() + .route( + "/hello", + get(hello) + .layer(middleware::from_fn(move |req, next| { + let key = auth::DecodingKey::from_secret(jwt_secret.as_ref()); + let validation = auth::Validation::default(); + async move { auth::verify_user(req, &key, validation, next).await } + })), + ) + .route( + "/login", + post(move |body: Json| { + let expiry_timestamp = Utc::now() + Duration::hours(48); + + auth::login( + body, + user_data.clone(), + jwt_secret, + expiry_timestamp.timestamp(), + ) + }), + ); + app +} + +``` +

You're all set!

## Features