export default defineEventHandler(async (event) => { try { // Validate the request body against the schema const variables = authLoginFormSchema.parse(await readBody(event)); // Execute the GraphQL operation to authenticate the user const { data, error } = await executeSchemaOperation(event, { operationName: "AuthLogin", variables, }); // Handle errors and validate the response data if (error) throw error; if (!data?.login) throw new Error("Identifiants invalides. Veuillez réessayer."); // Handle the login process by setting the session data if (!(await handleLogin(event, data.login))) { throw new Error("Une erreur est survenue lors de la connexion."); } return { success: true, message: "Connexion réussie" }; } catch (error) { const message = error instanceof Error ? error.message : "Une erreur est survenue lors de la connexion."; return { success: false, message }; } });