From f9051220ec148aa5ed743ae6900be9cc67913841 Mon Sep 17 00:00:00 2001 From: Larvey Date: Mon, 25 Dec 2023 20:42:09 -0500 Subject: [PATCH] Add Extra level of auth --- src/pages/api/auth/[...nextauth].js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pages/api/auth/[...nextauth].js b/src/pages/api/auth/[...nextauth].js index 88b9400..43df266 100644 --- a/src/pages/api/auth/[...nextauth].js +++ b/src/pages/api/auth/[...nextauth].js @@ -1,6 +1,8 @@ import NextAuth from "next-auth"; +import { connectToDatabase } from "../lib/database"; import GoogleProvider from "next-auth/providers/google"; + export const authOptions = { providers: [ GoogleProvider({ @@ -12,6 +14,14 @@ export const authOptions = { pages: { signIn: "/panel", }, + callbacks: { + async signIn({account, profile}) { + const db = await connectToDatabase(); + const collection = await db.collection("authorizedUsers"); + const data = await collection.distinct("email"); + return data.includes(profile?.email) + } + } }; export default NextAuth(authOptions);