fix: Properly handle signup errors
This commit is contained in:
parent
0de228e357
commit
360fbc644d
@ -59,7 +59,7 @@ export const actions = {
|
||||
status: 401,
|
||||
});
|
||||
} else {
|
||||
return setError(form, 'password', (e as APIError).body.code as string);
|
||||
return setError(form, 'password', (e as APIError).body.message as string);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import { redirect } from '@sveltejs/kit';
|
||||
import { fail, message, setError, superValidate } from 'sveltekit-superforms';
|
||||
import { zod } from 'sveltekit-superforms/adapters';
|
||||
import type { Actions } from './$types';
|
||||
import type { APIError } from 'better-auth/api';
|
||||
|
||||
export async function load({ request }) {
|
||||
const session = await auth.api.getSession({
|
||||
@ -26,6 +27,7 @@ export const actions = {
|
||||
const password = form.data.password;
|
||||
const name = form.data.username;
|
||||
|
||||
try {
|
||||
if (!form.valid) {
|
||||
return fail(400, { form });
|
||||
}
|
||||
@ -52,10 +54,9 @@ export const actions = {
|
||||
maxAge: 604800,
|
||||
secure: !dev,
|
||||
});
|
||||
} else {
|
||||
return setError(form, 'verify', 'Invalid email or password', {
|
||||
status: 401,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
return setError(form, 'verify', (e as APIError).body.message as string);
|
||||
}
|
||||
|
||||
return message(form, 'Successfuly signed in.');
|
||||
|
Loading…
Reference in New Issue
Block a user