
NextAuth.js Has a Free API That Adds Authentication to Any Next.js App in Minutes
NextAuth.js (now Auth.js) is the standard authentication library for Next.js. Its API handles OAuth, credentials, sessions, and JWTs with minimal configuration. Setup: One File, Full Auth // app/api/auth/[...nextauth]/route.ts import NextAuth from " next-auth " ; import Google from " next-auth/providers/google " ; import GitHub from " next-auth/providers/github " ; import Credentials from " next-auth/providers/credentials " ; const handler = NextAuth ({ providers : [ Google ({ clientId : process . env . GOOGLE_ID ! , clientSecret : process . env . GOOGLE_SECRET ! }), GitHub ({ clientId : process . env . GITHUB_ID ! , clientSecret : process . env . GITHUB_SECRET ! }), Credentials ({ credentials : { email : { label : " Email " , type : " email " }, password : { label : " Password " , type : " password " }, }, async authorize ( credentials ) { const user = await db . user . findUnique ({ where : { email : credentials . email } }); if ( user && await verify ( credentials . password , user
Continue reading on Dev.to React
Opens in a new tab



