Skip to content

Commit

Permalink
fix: missing correct error message on failed sigin
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas committed Jan 7, 2025
1 parent 7217e23 commit cc5adb3
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions client/src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';
import { GetServerSidePropsContext } from 'next';
import NextAuth, { getServerSession } from 'next-auth';
Expand Down Expand Up @@ -40,18 +39,9 @@ export const authOptions: NextAuthOptions = {
async authorize(credentials: Record<'email' | 'password', string> | undefined) {
if (!credentials) return null;
const { email, password } = credentials;
const { data } = await authenticationService.signIn(email, password);

try {
const { data } = await authenticationService.signIn(email, password);

return data;
} catch (err) {
if (axios.isAxiosError(err) && err.response) {
const errorMessage = err.response.data?.errors[0]?.title || 'Login failed';
throw new Error(errorMessage);
}
throw new Error('An unexpected error occurred');
}
return data;
},
}),
],
Expand Down

0 comments on commit cc5adb3

Please sign in to comment.