Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next-Auth: Cannot read property 'Adapter' of undefined

I get this error when I deploy a nextjs app in vercel.in dev mode every thing works fine but when I deploy my app in vercel I got this error.

This error probably come from next-auth, but I don't no why this show up.

My code in [...nextauth].js:

export default NextAuth({
session: {
    maxAge: 30 * 24 * 60 * 60,
    jwt: true,
    updateAge: 24 * 60 * 60
},
providers: [
    Providers.Credentials({
        async authorize(credentials) {
            try {
                await dbConnect();

                const findUser = await User.findOne({ email: credentials.email });
                if (!findUser) {
                    throw new Error('User not found.');
                }

                const comparePass = await comparePassword(credentials.password, findUser.password);
                if (!comparePass) {
                    throw new Error('Confirm password not match.');
                }
                return { email: credentials.email, isAdmin: findUser.isAdmin };
            } catch (error) {
                throw new Error(error.message);
            }
        }
    })
]});

This error will come when a request to /api/auth/session and /api/auth/_log

I'm glad for anyone can help me.

like image 533
Pouria Azhdari Avatar asked Oct 15 '22 21:10

Pouria Azhdari


1 Answers

What version of next-auth are you on? If it's 3.20.0 and above then the problem has something to do with the adapters. Try to check if you get something like this on your Function logs upon deployment:

Delpoyment bug

If so, try to uninstall @types/next-auth once you have updated next-auth to the latest version. It fixed this problem for me.

like image 144
Darryl Javier Avatar answered Oct 19 '22 08:10

Darryl Javier