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 authjsWant 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_URLPostgreSQL connection string (validated by lib/auth/env.ts).AUTH_SECRETSecret used to encrypt session JWTs.AUTH_GITHUB_IDGitHub OAuth app client ID (read automatically by Auth.js).AUTH_GITHUB_SECRETGitHub OAuth app client secret.AUTH_GOOGLE_IDGoogle OAuth client ID (read automatically by Auth.js).AUTH_GOOGLE_SECRETGoogle OAuth client secret.AUTH_DISCORD_IDDiscord OAuth app client ID (read automatically by Auth.js).AUTH_DISCORD_SECRETDiscord 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.