Login and Admin Access
Let users sign up and sign in, then open the admin area with your own account
Your signup and login pages are already included. Add a secret, connect email, and use your own account to open the admin area. Google, GitHub, and captcha are optional.
Before you start
- Initialize local D1 using the database guide.
- Configure Resend using the email guide, with an inbox you can use for verification.
- Local development runs at
http://localhost:3377.
Set up login
-
Add a random authentication secret to
.dev.vars. Copy a value from the generator:BETTER_AUTH_SECRET=replace-with-the-generated-secret -
Confirm your application URL in
.env:VITE_APP_URL=http://localhost:3377 -
Restart
pnpm dev, open/login/, switch to signup, and enter your name, email, and password. Signup and login share this page. -
Open the verification email and follow its link. Email/password accounts must be verified before login; verification signs you in automatically.
-
Refresh the homepage and confirm that your account menu appears.
If the login page shows 404, check that BETTER_AUTH_SECRET is filled in and the D1 setup is complete. If the verification email is missing, follow the email checks.
Set up your first administrator
Add your account email to .dev.vars:
SUPER_ADMIN_EMAIL=admin@example.comRestart and sign in with that email, then open /admin/. If the account does not exist yet, register and verify it first. You should see the admin navigation. Separate multiple administrator emails with commas.
The admin area manages users, orders, credit packages, site settings, and AI prices. See permissions to assign roles to other administrators.
Google login (optional)
-
Open Google Cloud Console, create a Web application OAuth client, and complete the consent screen as prompted.
-
Add
http://localhost:3377as an authorized origin and this redirect URI:http://localhost:3377/api/auth/callback/google -
Add the credentials to
.dev.vars:GOOGLE_CLIENT_ID=your-client-id GOOGLE_CLIENT_SECRET=your-client-secret -
Restart and complete a Google login. For production, add your real origin and
https://your-domain.com/api/auth/callback/google.
GitHub login (optional)
-
Open GitHub OAuth Apps and create an OAuth App.
-
Use
http://localhost:3377as the local Homepage URL and this callback:http://localhost:3377/api/auth/callback/github -
Add the credentials to
.dev.vars:GITHUB_CLIENT_ID=your-client-id GITHUB_CLIENT_SECRET=your-client-secret -
Restart and verify login. A production app uses your real domain and
https://your-domain.com/api/auth/callback/github; separate OAuth Apps can serve local and production environments.
The login page already shows social login buttons. To make one work, fill in both credentials and complete a test login.
Turnstile captcha (optional)
Create a widget in Cloudflare Turnstile, add your allowed local and production domains, then configure both files:
VITE_TURNSTILE_CAPTCHA_ENABLED=true
VITE_TURNSTILE_SITE_KEY=your-site-keyTURNSTILE_CAPTCHA_ENABLED=true
TURNSTILE_SECRET_KEY=your-secret-keyFill in both switches and both keys. Restart, then complete a signup or login with the captcha displayed.
Production and next steps
Upload authentication, email, and selected OAuth secrets to the production Worker. Set vars.VITE_APP_URL in wrangler.jsonc to your real domain; production builds read the same setting. Follow deployment for the full steps.
Once login works, configure credits or choose Stripe or Creem.