Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Next.js 15 Full-Stack & Production Deployment 22 mins read Free Lesson

Authentication in Next.js 15 with Auth.js (NextAuth v5)

Configure OAuth, Credentials providers, edge session verification, and protected route middleware.

Auth.js v5 in Next.js App Router

// auth.ts
import NextAuth from 'next-auth';
import GitHub from 'next-auth/providers/github';

export const { handlers, signIn, signOut, auth } = NextAuth({
    providers: [GitHub],
    callbacks: {
        authorized: async ({ auth }) => {
            return !!auth; // Logged in users can access protected pages
        }
    }
});