~/docs/backends/auth

Dashboard

Backends

Auth

Sign people in with a password, an email link or code, GitHub, Google, or as a guest.

Updated

2026-12-02

Source

apps/web/docs/backends/auth.mdx

ts

await phz.auth.signUp({ email, password });
await phz.auth.signInWithPassword({ email, password });

const { data } = await phz.auth.getUser();

phz.auth.onAuthStateChange((event, session) => {
  // SIGNED_IN, SIGNED_OUT, TOKEN_REFRESHED, …
});

await phz.auth.signOut();

In browsers the session is kept in localStorage and refreshed before it expires.

One email carries both a link and a 6-digit code:

ts

await phz.auth.signInWithOtp({
  email,
  options: { emailRedirectTo: 'https://app.example.com/welcome' },
});

await phz.auth.verifyOtp({ type: 'email', email, token: '123456' });

GitHub and Google

Turn a provider on under Auth → Settings → Providers, then:

ts

await phz.auth.signInWithOAuth({
  provider: 'github',
  options: { redirectTo: 'https://app.example.com/auth/callback' },
});

Guests

ts

await phz.auth.signInAnonymously();
// Later, keep their data and make it a full account:
await phz.auth.updateUser({ email, password });

Two-step verification

ts

const { data: factor } = await phz.auth.mfa.enroll({ factorType: 'totp' });
await phz.auth.mfa.challengeAndVerify({ factorId: factor.id, code });

Row-level security policies can require aal2 through the aal claim.

Server rendering

@pherwerz/cloud/ssr keeps the session in cookies, so the browser, the proxy and Server Components share one sign-in. Make one server client per request, and use getUser() or getClaims() before trusting a user on the server: getSession() only reads the cookie.