tetthys-auth
Simple Usage Guide for Leptos + Axum SSR
tetthys-auth is a minimal, framework-agnostic authentication core.
In a Leptos 0.8+ + Axum SSR setup, it lets you access authentication state anywhere via async helpers, without globals or framework coupling.
This guide focuses only on what you must implement and how to wire it.
What tetthys-auth Does (In One Sentence)
It resolves the current
user_idper request, optionally loads a User record, and exposes simple async helpers.
That’s it.
What tetthys-auth Does NOT Do
- No
Usertrait - No roles or permissions
- No cookie parsing logic
- No database logic
- No middleware magic
All of that stays in your app, not in this crate.
Core Helpers You Will Use
Once wired, these work anywhere (SSR render, server functions, services):
.await?
.await?
.await?
.await?
What You Need to Implement (3 Small Pieces)
1) Resolve user_id from the request
use Body;
use Request;
use AuthError;
;
Purpose: ➡ “Is this request authenticated? If yes, what is the user_id?”
2) Load the User by user_id (optional but recommended)
use ;
;
Notes:
- Returning
Noneis valid (deleted user, stale session). - In that case
auth_user()returnsNone.
3) Mutate the session using user_id
use ;
;
Purpose: ➡ “Persist or clear authentication state.”
Wiring in Axum (One Time)
Create shared adapter state:
use Arc;
use AuthAdapterState;
let auth_state = new;
Attach it to your Axum app state.
Server Functions Route (Required)
use post;
use leptos_server_fns_handler_with_auth;
new
.route
.with_state;
This makes auth helpers work inside #[server] functions.
SSR Rendering Route (Required)
use leptos_ssr_render_handler_with_auth;
new.fallback;
This makes auth helpers work during SSR rendering.
Using Auth Helpers (Examples)
Get current user id
let user_id = .await?;
Get current user
if let Some = .await?
Require authentication
let user = .await?;
Sign in
.await?;
Sign out
.await?;
Mental Model (Keep This)
- Authentication = user_id exists or not
- Session = store user_id
- User = optional materialization
- Everything is request-scoped
- No globals, no magic
Common Errors
| Error | Meaning |
|---|---|
MissingContext |
Auth not injected into SSR/server-fns |
Unauthenticated |
No user_id |
MissingSession |
sign-in/out called without session mutator |
That’s It
If you understand:
- “I resolve user_id”
- “I load user by id”
- “I store/clear user_id”
…then you understand tetthys-auth.