improve auth error handling to not leak internal details

This commit is contained in:
hiperman
2026-02-22 02:11:46 -05:00
parent 92b65309e8
commit 37e69a35db
+7 -5
View File
@@ -7,13 +7,13 @@ export const signup = form(signupSchema, async (user, issue) => {
try { try {
await auth.api.signUpEmail({ body: user }); await auth.api.signUpEmail({ body: user });
} catch (error: any) { } catch (error: any) {
console.error(error) console.error('Signup error:', error?.body?.code);
// Use invalid to mark fields as invalid
if (error?.body?.code === 'USER_ALREADY_EXISTS') { if (error?.body?.code === 'USER_ALREADY_EXISTS') {
invalid(issue.email('An account with this email already exists')); invalid(issue.email('An account with this email already exists'));
} }
// Generic error for the whole form // Show generic error message on unknown errors
invalid(error?.body?.message || error?.message || 'Signup failed'); invalid('Unable to create account. Please try again.');
} }
redirect(307, `/`); redirect(307, `/`);
@@ -24,11 +24,13 @@ export const login = form(loginSchema, async (user, issue) => {
const { request } = getRequestEvent(); const { request } = getRequestEvent();
await auth.api.signInEmail({ body: user, headers: request.headers }); await auth.api.signInEmail({ body: user, headers: request.headers });
} catch (error: any) { } catch (error: any) {
console.error('Login error:', error?.body?.code);
// Handle invalid credentials // Handle invalid credentials
if (error?.body?.code === 'INVALID_EMAIL_OR_PASSWORD') { if (error?.body?.code === 'INVALID_EMAIL_OR_PASSWORD') {
invalid('Invalid email or password'); invalid('Invalid email or password');
} }
// Generic error // Show generic error message on unknown errors
invalid('Login failed'); invalid('Login failed');
} }