New:New releases:CLIcreate-clubedge-app v0.49.1·Clubedge Starter v0.32.0

Clubedge Starter Docs

Authentication

Supabase Auth, Better Auth, Firebase Authentication, or Appwrite, behind one AuthProvider interface.

Choose with --auth supabase (default), --auth better-auth, --auth firebase, --auth appwrite, or --auth none. Firebase and Appwrite need Starter v0.21.0 or newer.

With Next.js and TanStack Start, every provider gives you server-verified sessions in secure cookies, a protected dashboard, rate-limited sign-in, and an account settings page with display name, password change, and account deletion. Password reset by email comes with Supabase Auth and Appwrite, and with Better Auth and Firebase when the project has an email module. Pages and forms never touch the provider SDK: they go through the AuthProvider interface in packages/auth.

A React + Vite frontend with an API works differently: see A frontend and its API.

Until the provider is configured, the dashboard stays viewable as a demo and the login page explains what is missing. Once it is configured, the dashboard redirects signed-out visitors to the login page.

Create or select a Supabase project and copy its URL and publishable key from the project's API settings into the Supabase variables:

Next.jsTanStack Start
NEXT_PUBLIC_SUPABASE_URLSUPABASE_URL
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYSUPABASE_PUBLISHABLE_KEY

Authentication runs on the server, which validates every user with Supabase, and the publishable key is all sign-in needs. To let users delete their account from the settings page, also set SUPABASE_SECRET_KEY to a secret key from the same settings. It stays on the server, so never give it a NEXT_PUBLIC_ prefix.

Redirect URLs

In Supabase Auth URL configuration, add this redirect URL for local email confirmation and password reset links:

http://localhost:3000/auth/callback**

For deployed environments, add your deployed origin followed by /auth/callback**. The ** lets links carry the page to open next, such as /reset-password.

Supabase emails

Supabase sends the confirmation and password reset emails itself. Configure its SMTP settings in the Supabase project to send them from your own domain.

Changing or resetting a password signs out every other session, with every provider.

A frontend and its API

On a React + Vite frontend with Hono or FastAPI (Starter v0.24.0 or newer), the browser signs in with the provider, and the API checks the user on every request it serves. The frontend has the landing page, the dashboard, the sign-in and sign-up page (/login), /forgot-password, /reset-password, and the account settings page (/settings, Starter v0.25.0 or newer). The dashboard reads the user from the API's /api/session, and once the provider is configured it redirects signed-out visitors to /login.

The frontend's settings are public VITE_* variables in apps/web/.env.local, and the API's are in apps/api/.env.local. Vite compiles the VITE_* values into the build, so in production set them where the frontend is built: as Docker build arguments, or on Railway as the frontend service's variables.

FrontendAPI
VITE_SUPABASE_URLSUPABASE_URL
VITE_SUPABASE_PUBLISHABLE_KEYSUPABASE_PUBLISHABLE_KEY

The browser keeps the Supabase session and sends its access token to the API as a bearer token. The API asks Supabase Auth for the token's user on each request. Sign-in needs no secret key. To let users delete their account from the settings page, set SUPABASE_SECRET_KEY in apps/api/.env.local; only the API uses it.

Sign-up confirmation links open /login and password reset links open /reset-password, so add both to Supabase Auth's redirect URLs, locally and for your deployed origin:

http://localhost:3000/login**
http://localhost:3000/reset-password**

In the mobile app

A mobile app (Starter v0.27.0 or newer) keeps its session on the device and sends it with each call, since the website's cookies never reach it. With Better Auth, it signs in with bearer tokens, which the API checks as it checks the cookie; with Appwrite, add a Web platform for the hostname localhost too. Emailed links open the website. See Sign-in for each provider.

In the native app

The native app (Starter v0.28.0 or newer) signs in with Supabase Auth or Better Auth, or has no sign-in: the CLI refuses Firebase and Appwrite with --mobile expo. It keeps its session on the device. Better Auth's Expo plugin keeps the session cookie in the device's secure storage, and the server trusts the app's address scheme; Supabase keeps its session in the app's storage, and the app sends the access token to the API. Emailed links open the website, or the app in a project without a website. See Sign-in.

Without a website

In a project without a website (Starter v0.28.0 or newer), clients sign in and send the session or token with each request, and the API checks the user, with every provider. The settings go in apps/api/.env.local:

  • Better Auth runs in the Hono API, at /api/auth, once BETTER_AUTH_SECRET, at least 32 random characters, is set; pnpm check:env refuses a shorter one. BETTER_AUTH_URL is the API's public URL. FastAPI can't run it, so the CLI refuses --auth better-auth with --api fastapi there.
  • Supabase Auth: SUPABASE_URL and SUPABASE_PUBLISHABLE_KEY, and SUPABASE_SECRET_KEY for account deletion. For emailed links to open the native app, add its address scheme to the Redirect URLs, such as my-product://**.
  • Firebase and Appwrite: clients send Firebase's ID token, or a JWT from Appwrite, as a bearer token, and the API accepts only confirmed addresses. The native app doesn't sign in with either.

The API keeps the account endpoints, the display name and account deletion, as with a frontend; passwords change with the provider. See Sign-in.

The settings page

With either API, the settings page has the display name, the password change, and account deletion, as on Next.js and TanStack Start (with FastAPI, Starter v0.26.0 or newer). The password change goes to the provider, in the browser or in Better Auth's server, which signs out the user's other sessions. The display name and account deletion go through the API, which keeps the app's data: deletion checks the password (10 tries a minute per user), removes the user's app data, then deletes the user from the provider. With an active subscription, it refuses until the user cancels it.

Another provider

Pages and forms depend on the AuthProvider interface in packages/auth, so another provider is a new package that implements it and a variant of src/server/auth.ts. Prove it with the conformance suite every provider runs, which covers sign-up and sign-in, one answer for a wrong password and an unknown address, sign-out, password reset through the emailed link, password changes, and account deletion:

packages/auth-my-provider/src/conformance.test.ts
import { describeAuthProvider } from "@clubedge/auth/conformance";
import { createMyAuth } from "./index";

describeAuthProvider("my-provider", () => ({
  browser: () => createMyAuth({ cookies: cookieJar() }),
  // The token from the latest reset email to this address, as a person clicking it would get.
  openResetLink: async (email) => readResetToken(email),
}));

Provider user ids are stored as text in users.auth_user_id (Starter v0.21.0 or newer), so they need not be UUIDs.

On a frontend and its API, a provider is two variants instead: a browser client implementing AuthClient (apps/web/src/lib/auth-client.ts), and the API's check: getCurrentUser, canDeleteAccount, and deleteAccount in apps/api/src/server/auth.ts with Hono, or get_current_user, can_delete_account, and delete_account in apps/api/src/clubedge_api/auth.py with FastAPI.

Protect routes and pages

Make authenticated server routes call getCurrentUser() or requireUser() from @/server/auth (the latter throws a 401 AppError), and protect pages with getPageUser, which redirects signed-out visitors to /login. Do not treat cookie contents alone as proof of identity.

On a frontend and its API, and without a website, the API protects the data. Its routes get the user from the dependencies the composition root passes them, as /api/session does: dependencies.getCurrentUser(request) with Hono, dependencies.get_current_user(request) with FastAPI. It returns null (None) for a signed-out request, so answer 401 then. The provider's check is in apps/api/src/server/auth.ts or apps/api/src/clubedge_api/auth.py. The frontend's redirect to /login is a convenience, not a check.

Framework differences

ConcernNext.jsTanStack Start
Sign-in and sign-upServer actionsForm posts to /auth/sign-in and /auth/sign-up server routes
Session refreshsrc/proxy.ts, with Supabase Auth and Better AuthRequest middleware in src/start.ts, with every provider
Cross-site protectionBuilt into server actionscreateCsrfMiddleware in src/start.ts

How is this guide?