diff --git a/server/api/login.post.ts b/server/api/login.post.ts index 849d3d7..4c6fe53 100644 --- a/server/api/login.post.ts +++ b/server/api/login.post.ts @@ -5,21 +5,34 @@ const bodySchema = z.object({ password: z.string(), }) +function check_login(user: string,pwd: string): number { + /*const r = $fetch("http://localhost:5000/login", { + method: "POST", + body: JSON.stringify({user: user, pwd: pwd}), + })*/ + if (user === "tomas@suricatingss.xyz" && pwd === "tomas190905") + return 0; // 0 = no errror = success + else return 1; +} + export default defineEventHandler(async (event) => { const { email, password } = await readValidatedBody(event, bodySchema.parse) - if (email === 'admin@admin.com' && password === 'iamtheadmin') { - // set the user session in the cookie - // this server util is auto-imported by the auth-utils module - await setUserSession(event, { - user: { - name: 'John Doe', - }, - }) - return {} + const response = (check_login(email, password)); + switch (response) { + case 0: + // set the user session in the cookie + // this server util is auto-imported by the auth-utils module + await setUserSession(event, { + user: { + name: 'John Doe', + }, + }) + return ""; + case 1: + setResponseStatus(event, 403); + return "Incorrect login"; + + } - throw createError({ - statusCode: 401, - message: 'Bad credentials', - }) })