Created
April 21, 2023 06:46
-
-
Save arye321/9f8412833ce7062718be156d7fe2f9f9 to your computer and use it in GitHub Desktop.
nextauth google mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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