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