login complete (its still dummy)

This commit is contained in:
suricatingss
2025-12-08 22:22:07 +00:00
parent eea47b714a
commit b857c81624

View File

@@ -5,21 +5,34 @@ const bodySchema = z.object({
password: z.string(), 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) => { export default defineEventHandler(async (event) => {
const { email, password } = await readValidatedBody(event, bodySchema.parse) const { email, password } = await readValidatedBody(event, bodySchema.parse)
if (email === 'admin@admin.com' && password === 'iamtheadmin') { const response = (check_login(email, password));
// set the user session in the cookie switch (response) {
// this server util is auto-imported by the auth-utils module case 0:
await setUserSession(event, { // set the user session in the cookie
user: { // this server util is auto-imported by the auth-utils module
name: 'John Doe', await setUserSession(event, {
}, user: {
}) name: 'John Doe',
return {} },
})
return "";
case 1:
setResponseStatus(event, 403);
return "Incorrect login";
} }
throw createError({
statusCode: 401,
message: 'Bad credentials',
})
}) })