Backend/Sign-in

Sign-in

Replace the demo sign-in with real accounts. This guide uses Supabase Auth as the example, since it pairs with the Database guide; Auth.js and Clerk follow the same steps.

How the demo sign-in works

The sign-in screens call a handful of helpers in src/lib/auth.ts, and nothing else. The helpers pretend to talk to a server: accounts are saved in the browser and every emailed code is 123456.

ScreenHelpers it callsReplace with
/loginsignInEmail and password sign-in
/registersendCode, verifyCode, createAccountSign-up with an email code
/forgotsendCode, verifyCode, resetPasswordPassword reset
Profile setup (after sign-up)saveProfileSaving the profile to your database
Continue with GoogleNone: it opens the appGoogle sign-in (OAuth) from your provider

Connect a sign-in provider

Keep the helper names and change what's inside them, and the screens, errors and loading states keep working:

src/lib/auth.ts
// createClient: the browser client from Supabase's Next.js guide
export async function signIn(email: string, password: string) {
  const supabase = createClient()
  const { error } = await supabase.auth.signInWithPassword({ email, password })
  return !error
}
  • Codes. Supabase can email a 6-digit code (signInWithOtp, then verifyOtp), which fits the existing code screens. Its emails send a link by default; switch the email template to show the code.
  • Google. Turn on Google in your provider's dashboard and call its OAuth sign-in from the Continue with Google button.
  • Other providers. With Auth.js or Clerk the steps are the same: sign-in, sign-up, codes and reset go inside the same helpers. Clerk also offers ready-made screens, if you'd rather replace Accordee's.

Protect the app

In the demo anyone can open the app screens. Once sign-in is real, check the session on the server and send signed-out visitors to /login, either in the layout that wraps the app screens or in a Next.js proxy (called middleware in older versions). Supabase's Next.js guide includes the proxy that keeps sessions fresh.

Redirecting isn't enough on its own. Your database rules and Route Handlers must also check who's signed in.

The signed-in user

The demo user, Jane, comes from CURRENT_USER in src/lib/data/workspace.ts, and her profile from the saved preferences. Load the signed-in person's name, email and avatar from your provider and database instead, and save profile changes there too.

Before launch

  • Remove DEMO_ACCOUNT, DEMO_RESET_CODE and the demo hints on the sign-in screens.
  • Remove the Try out the demo button, or point it at a real demo workspace.
  • Turn on email confirmation and sensible password rules in your provider.
  • Test sign-up, sign-in, reset and sign-out on a phone and in a private window.