generated from pascalmartineau/wp-skeleton
refactor: use onServerResponse for auth instead of server api
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user