Next.js Discord

Discord Forum

NextAuth v5 signIn not triggering authorize method in Credentials Provider

Unanswered
Prairie yellowjacket posted this in #help-forum
Open in Discord
Prairie yellowjacketOP
Everything was working fine until I tested it again, now even credentials provider doesn't work for me, my authorize function doesn't trigger, does anyone know what can be wrong?

    signIn('credentials', {
            redirect: false,
            username: data.email,
            password: data.password
        })
            .then((res) => {
                if (res?.error) throw new Error('CredentialsSignin');
            })
            .catch((error) => {
                setError('Incorrect username or password.');
                console.log('error', error.message);
    


export const {
    handlers: { GET, POST },
    auth
} = NextAuth({
Credentials({
            name: 'credentials',
            async authorize(credentials) {
                if (!credentials?.email || !credentials?.password) return null;
                const { email, password } = credentials;
                console.log('here');
                const res = await fetch(process.env.NEXT_PUBLIC_BACKEND_API + '/auth/login', {
                    method: 'POST',
                    body: JSON.stringify({
                        email: email,
                        password
                    }),
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
                console.log(res);
                if (!res.ok) {
                    throw new Error('User name or password is not correct');
                }
                const user = await res.json();

                return user;
            }
        })
});
        });

0 Replies