refactor: use onServerResponse for auth instead of server api

This commit is contained in:
2025-09-18 10:23:09 -04:00
parent a661350e1c
commit c82abe88e4
11 changed files with 57 additions and 139 deletions

View File

@@ -22,11 +22,12 @@ export function useAuth() {
required: true,
},
];
async function onLoginSubmit({ data }: FormSubmitEvent<LoginOutput>) {
async function onLoginSubmit({ data: args }: FormSubmitEvent<LoginOutput>) {
try {
const result = await $fetch<{ success: boolean; message?: string }>("/api/login", { method: "POST", body: data });
if (!result.success) {
throw new Error(result.message || "Une erreur est survenue.");
const { data, errors } = await useGraphqlMutation("login", args);
if (errors.length || !data.login) {
console.error(errors);
throw new Error("Une erreur est survenue.");
}
await router.push(redirect);
await refreshUserSession();