Anonymous / Guest Auth
Guest sessions let users try your app before committing to registration. When ready, they can upgrade to a full account without losing their data.
use authx_plugins::AnonymousService;
let svc = AnonymousService::new(store.clone(), events.clone(), 3600);Create a guest session
Section titled “Create a guest session”let (user, session, token) = svc.create_guest("127.0.0.1").await?;
// user.email is "guest_<uuid>@authx.guest" — a synthetic placeholder// user.metadata contains {"guest": true}// token is the session token to send to the clientUpgrade to a real account
Section titled “Upgrade to a real account”let upgraded_user = svc.upgrade( guest_user_id, "alice@example.com", "securepassword123",).await?;// Err(AuthError::Forbidden) if user_id is not a guest// Err(AuthError::EmailTaken) if email is already usedAfter upgrade, the user’s existing sessions and data remain intact — only their email and credentials change.