login complete (its still dummy)
This commit is contained in:
@@ -5,10 +5,22 @@ 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));
|
||||||
|
switch (response) {
|
||||||
|
case 0:
|
||||||
// set the user session in the cookie
|
// set the user session in the cookie
|
||||||
// this server util is auto-imported by the auth-utils module
|
// this server util is auto-imported by the auth-utils module
|
||||||
await setUserSession(event, {
|
await setUserSession(event, {
|
||||||
@@ -16,10 +28,11 @@ export default defineEventHandler(async (event) => {
|
|||||||
name: 'John Doe',
|
name: 'John Doe',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return {}
|
return "";
|
||||||
|
case 1:
|
||||||
|
setResponseStatus(event, 403);
|
||||||
|
return "Incorrect login";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
throw createError({
|
|
||||||
statusCode: 401,
|
|
||||||
message: 'Bad credentials',
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user