freeauthv0.3.1

Auth.js (NextAuth v5)

Auth.js v5 with email/password plus your pick of GitHub, Google and Discord sign-in, JWT sessions, a Prisma adapter, roles and route protection.

$npx cnippet-stack init authjs

Want to understand the code? Read the step-by-step guide on next.cnippet.dev →

supports
Next.js
16
Router
app
ORM
prisma

Requires: prisma

prompts
  • Which OAuth providers? (email and password is always on)(multiselect)
    GitHubGoogleDiscord
  • Add login, register, dashboard and profile pages?(confirm)
environment variables
  • DATABASE_URL PostgreSQL connection string (validated by lib/auth/env.ts).
  • AUTH_SECRET Secret used to encrypt session JWTs.
  • AUTH_GITHUB_ID GitHub OAuth app client ID (read automatically by Auth.js).
  • AUTH_GITHUB_SECRET GitHub OAuth app client secret.
  • AUTH_GOOGLE_ID Google OAuth client ID (read automatically by Auth.js).
  • AUTH_GOOGLE_SECRET Google OAuth client secret.
  • AUTH_DISCORD_ID Discord OAuth app client ID (read automatically by Auth.js).
  • AUTH_DISCORD_SECRET Discord OAuth app client secret.
manual steps
  • Migrate the auth tablesrequired

    Run `prisma migrate dev --name authjs` to create the auth tables.

  • Create the OAuth appsrequired

    Create an OAuth app for each provider you picked, with the callback URL `<your-url>/api/auth/callback/<provider>` (e.g. `/api/auth/callback/github`), then set AUTH_<PROVIDER>_ID and AUTH_<PROVIDER>_SECRET.