🤠 Auth.js Setup

Add auth.js for user authentication

💎 Generate NEXTAUTH_SECRET https://generate-secret.vercel.app/32

Auth.js Setup

Add Auth.js to your project.

command line
npm install next-auth

# Generate a random token
# add this value as NEXTAUTH_SECRET in .env
openssl rand -base64 32

Create a Catchall Route

Create the following route file api/auth/[...nextauth]/route.ts.

import NextAuth from 'next-auth';
import type { NextAuthOptions } from 'next-auth';
import GithubProvider from 'next-auth/providers/github';

export const authOptions: NextAuthOptions = {
  providers: [
      clientId: process.env.GITHUB_ID!,
      clientSecret: process.env.GITHUB_SECRET!,

const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };

Questions? Let's chat

Open Discord