My Next-auth logIn() function appears to be stuck endlessly on /api/auth/providers, as shown in this image.
It seems that the async authorize(credentials)
part is not being executed at all, as none of the console.log
statements are working.
/pages/api/auth/[...nextauth].js
import Providers from 'next-auth/providers';
import connectDB from '../../../lib/connectDB';
import User from '../../../models/User';
export default NextAuth({
//Configure JWT
session: {
jwt: true,
},
//Specify Provider
providers: [
Providers.Credentials({
async authorize(credentials) {
console.log('====THIS MESSAGE IS NOT SHOWN ON CONSOLE====')
connectDB();
const user = await User.findOne({
email: credentials.email,
});
console.log(user);
if (user & (await user.matchPassword(credentials.passowrd))) {
client.close();
return { email: user.email };
}
client.close();
return null;
},
}),
],
});
Client Side
const onLogin = async (values) => {
const status = await signIn('credentials', {
redirect: false,
email: values.email,
password: values.password,
});
console.log('Login Status: ', status);
// This is not logged as well, due to /api/auth/providers being stuck
}