NextAuth to Vercel with Google Provider + MongoDB
Unanswered
Smalandstövare posted this in #help-forum
SmalandstövareOP
Hi, I'm trying to deploy a project with the Google Provider (using NextAuth) to Vercel. However, on deployment, I receive this error. I followed a YouTube tutorial, and they didn't state the session type, nor other tutorials I had a quick look at.
Code
Type error: Binding element 'session' implicitly has an 'any' type.Code
import NextAuth from "next-auth/next";
import GoogleProvider from "next-auth/providers/google";
import { connectDB } from "@/utils/database";
import User from "@/models/user";
const authOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}),
],
callbacks: {
async session({ session }) {
console.log(session);
const sessionUser = await User.findOne({
email: session.user.email,
});
console.log(sessionUser);
session.user = {
name: sessionUser?.name,
_id: sessionUser._id,
username: sessionUser.username,
email: sessionUser.email,
};
return session;
},
secret: process.env.NEXTAUTH_SECRET as string,
}
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };