Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';

export const signInFormSchema = z.object({
email: z.string().min(1, 'Please enter your email.').transform((val) => val.trim().toLowerCase()),
email: z.string().email('Please enter your email.').transform((val) => val.trim().toLowerCase()),
password: z.string().min(1, 'Please enter your password.').transform((val) => val.trim()),
});

Expand Down
16 changes: 15 additions & 1 deletion src/services/auth/useSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ type SignInInput = {
password: string;
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mapConvexAuthError(error: any): string {
if (!error?.message) {
return 'An unexpected error occurred. Please try again.';
}

if (error.message.includes('InvalidAccountId')) {
return 'Your email or password is incorrect.';
}

return 'Sign-in failed. Please check your details and try again.';
}

export const useSignIn = () => {
const { signIn } = useAuthActions();
const navigate = useNavigate();
Expand Down Expand Up @@ -47,8 +60,9 @@ export const useSignIn = () => {
flow: 'signIn',
}).catch((error) => {
setLoading(false);
const description = mapConvexAuthError(error);
console.error(error);
toast.error('Error', { description: error.message });
toast.error('Error', { description: description });
});
},
loading,
Expand Down