login complete (its still dummy)
This commit is contained in:
@@ -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',
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user