Documentation
Authentication
StartupKit ships with email + password auth, Google OAuth, email verification, password reset, onboarding, and middleware-based route protection powered by NextAuth.js.
Architecture Overview
- NextAuth configuration:
src/lib/auth.tswires the Prisma adapter, Google provider and Credentials provider. - Database models: Defined in
prisma/schema.prisma(User, Account, Session, VerificationToken, PasswordResetToken). - UI flows: All auth pages live in
src/app/(auth)and use shadcn/ui components for consistency. - Middleware:
src/middleware.tsguards dashboard routes, onboarding, and optional subscription enforcement.
Flows
Registration
- User signs up at
/registerwith email/password or Google. - Email/password users receive a verification link (Resend or console log).
- Google users have
emailVerifiedset automatically. - Everyone is redirected to
/dashboard/onboardinguntil they finish the profile form.
Login
Credentials are validated with bcrypt via Prisma. Users must have emailVerified set. OAuth users can log in immediately after the Google callback.
Password Reset
- Users request a reset at
/forgot-password. - A
PasswordResetTokenis created and emailed (or logged in dev). - The reset page verifies the token and lets the user set a new password.
Configuration Steps
- Fill out the env vars in
.env(DATABASE_URL,NEXTAUTH_SECRET, Google, Resend, etc.). - Generate Prisma client + push schema.
- Start the dev server and register your first account.
- Visit
/dev-toolsto mark the account verified if you have not hooked up Resend yet.
Extending Authentication
- Add providers: Import any NextAuth provider inside
src/lib/auth.tsand append it to theprovidersarray. Remember to set env vars for the provider keys. - Custom fields: Add columns to the
Usermodel in Prisma, runnpx prisma db push, then update onboarding + dashboard forms to collect/store values. - Session data: Use the
jwtandsessioncallbacks to expose extra fields to the client.
Testing Checklist
- Create two accounts: email/password and Google.
- Ensure the middleware forces onboarding before hitting
/dashboard. - Confirm the password reset email logs the correct URL locally.
- Toggle
ENABLE_SUBSCRIPTION_ENFORCEMENTto verify gated dashboards still respect auth.