I’m trying to implement the email,password login in the next app using next-auth v5.
In the NextAuth function inside authorize, I tried various methods to throw a custom error message that can passed to the user to show what’s going wrong with the credentials.
export const { auth, handlers, signIn, signOut } = NextAuth({
session: {
strategy: 'jwt',
},
pages: {
signIn: '/auth/login',
},
providers: [
CredentialsProvider({
credentials: {
email: {},
password: {},
},
async authorize({ email, password }) {
try {
throw new Error(
JSON.stringify({ errors: 'user.errors', status: false })
);
} catch (error) {
throw new Error(
JSON.stringify({ errors: ' catch user.errors', status: false })
);
}
},
}),
],
but every time
it shows this error message, instead showing the error message
But in the server console it show my custom error message.
I want to get that error message to the client side and show that error message to the user.