Skip to content

Instantly share code, notes, and snippets.

@arye321
Created April 21, 2023 06:46
Show Gist options
  • Save arye321/9f8412833ce7062718be156d7fe2f9f9 to your computer and use it in GitHub Desktop.
Save arye321/9f8412833ce7062718be156d7fe2f9f9 to your computer and use it in GitHub Desktop.
nextauth google mongo
import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { MongoDBAdapter } from "@next-auth/mongodb-adapter";
import clientPromise from "../../../lib/mongodb";
if (!process.env.GOOGLE_CLIENT_ID){
throw new Error("Please add GOOGLE_CLIENT_ID to .env.local")
}
if (!process.env.GOOGLE_CLIENT_SECRET){
throw new Error("Please add GOOGLE_CLIENT_SECRET to .env.local")
}
if (!process.env.SECRET){
throw new Error("Please add SECRET to .env.local")
}
export default NextAuth({
adapter: MongoDBAdapter(clientPromise),
// Configure one or more authentication providers
session: {
// maxAge: 60 * 24 * 60 * 60, // set cookie for 60 days, default is 30
strategy: "jwt",
},
providers: [
// GithubProvider({
// clientId: process.env.GITHUB_ID,
// clientSecret: process.env.GITHUB_SECRET,
// }),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
// ...add more providers here
],
secret: process.env.SECRET,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment