Home
Menu

Authentication

How sign-in works in smiet — an emailed code and passkeys, no identity provider

Overview

smiet runs its own login through the oxidt-auth crate in local mode: an emailed code proves that you own the address and creates the account on first use; passkeys are verified by smiet itself, which is the WebAuthn Relying Party. There is no identity provider. Authentication is session-based using tower-sessions with PostgreSQL as the session store.

Auth Flow

1

Email, or a passkey straight away

The login page offers passkey autofill on the email field (navigator.credentials.get with conditional UI), so a browser that holds a passkey for smiet can sign in without typing anything. Otherwise the page POSTs the address to /auth/session/start.

2

Branch on what the account has

  • Has a passkey → the server returns WebAuthn request options; the browser runs the ceremony and POSTs the assertion to /auth/session/passkey/verify.
  • No passkey, or a new address → a 6-digit code is mailed and verified at /auth/session/otp/verify. A verified code for an unknown address creates the account (registration is open).
3

Session cookie is set

The server records the user via AuthUserStore and stores the session in PostgreSQL. The signed cookie is HTTP-only and (in production) secure + SameSite=Lax.

4

Passkey offer

After a code login the page offers to enrol a passkey once. Passkeys can also be added and removed under Settings → Passkeys; the emailed code always remains as a fallback.

Key Components

Server Side

The auth crate defines three traits that the main app implements:

rust
// AuthUserStore — find or create users, post-login redirect logic
#[async_trait]
pub trait AuthUserStore: Send + Sync {
    async fn get_user_by_id(&self, id: &str) -> AuthResult<Option<AuthUser>>;
    async fn get_user_by_email(&self, email: &str) -> AuthResult<Option<AuthUser>>;
    async fn create_user(&self, user: NewAuthUser) -> AuthResult<AuthUser>;
    // ... and a few more
}

// AuthEmailSender — deliver the codes via SMTP
#[async_trait]
pub trait AuthEmailSender: Send + Sync {
    async fn send_verification_code(&self, to_email: &str, code: &str, expires_in_minutes: u32)
        -> AuthResult<()>;
}

// AuthPasskeyStore — WebAuthn credentials in the `user_passkeys` table
#[async_trait]
pub trait AuthPasskeyStore: Send + Sync {
    async fn find_passkey_by_credential_id(&self, credential_id: &str) -> AuthResult<Option<StoredPasskey>>;
    async fn insert_passkey(&self, user_id: &str, passkey: NewPasskey) -> AuthResult<()>;
    // ... list, touch, delete
}

Reading the session

Pages read the signed-in user from the session that the auth routes write:

rust
let user = auth::topcoat::user_session(cx).await?.data()?;

Pages under the dashboard go through require_user, which redirects a signed-out visitor to /login and back afterwards.

Configuration

Variable Description
BASE_URL Public origin. The passkey Relying Party id is its host, and POSTs to the auth routes must carry a matching Origin.
SMTP_HOST / SMTP_PORT / SMTP_FROM (+ SMTP_USER / SMTP_PASSWORD) Where the codes are sent from.
TRUST_PROXY_HEADERS Set to true when running behind a reverse proxy so auth rate limiting trusts X-Forwarded-For.
DEV_LOGIN Debug builds only: a "Dev login (local only)" button on /login that signs in as dev@localhost without an email code.

Security middleware

All routes mounted by local_auth_router are wrapped with:

  • Rate limiting — per-client-IP quotas, stored in PostgreSQL so they hold across replicas, plus a per-session cap on code attempts.
  • CSRF Origin check — POST requests must carry Origin (or Referer) matching BASE_URL.

Both come from the shared oxidt-auth crate; smiet supplies the PostgreSQL rate-limit store.