feat: Initial login / logout API endpoints

This commit is contained in:
2026-03-26 13:51:37 -04:00
parent 9bb6b40191
commit bd108f69a4
10 changed files with 322 additions and 19 deletions

View File

@@ -0,0 +1,27 @@
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 };
}
});