My app was working fine until today when I encountered an error while trying to log in with Google using NextAuth. The error message I received is shown in the screenshots below:
https://i.sstatic.net/FFTKc.png
https://i.sstatic.net/juZko.png
The terminal output for this issue is as follows:
https://i.sstatic.net/9TS5v.png
I have attempted to resolve the problem by changing the client ID and Secret, but the issue persists.
Below is the code snippet from my NextAuth configuration:
const authOptions = {
providers: [
// OAuth authentication providers...
GoogleProvider({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
authorizationUrl:
"https://accounts.google.com/o/oauth2/v2/auth?propmt=consent&access_type=offline&response_type=code",
})
],
secret: process.env.NEXTAUTH_SECRET,
adapter: MongoDBAdapter(clientPromise),
callbacks: {
async signIn({ account, profile }) {
if (account.provider === "google") {
return profile.email_verified && profile.email.endsWith("@gmail.com")
}
return true // Do different verification for other providers that don't have `email_verified`
},
session: ({session, token, user}) => {
if (adminEmails.includes(session?.user?.email)) {
return session;
}
else {
return false;
}
},
},
}
export default NextAuth(authOptions)
export async function isAdminRequest(req,res) {
const session = await getServerSession(req,res,authOptions);
if (!adminEmails.includes(session?.user?.email)) {
res.status(401);
res.end();
throw 'not admin';
}
}