31 lines
729 B
TypeScript
31 lines
729 B
TypeScript
import { globalUserObject } from "../middleware/login";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const body = await readBody(event)
|
|
|
|
let correctUsername;
|
|
let correctPassword;
|
|
if (globalUserObject !== null) {
|
|
correctUsername = globalUserObject.username;
|
|
correctPassword = globalUserObject.password;
|
|
}
|
|
|
|
let authorized = false;
|
|
|
|
if (body.username == correctUsername && body.password == correctPassword) {
|
|
authorized = true;
|
|
}
|
|
|
|
if (!authorized) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: 'Username or password not valid.',
|
|
})
|
|
}
|
|
|
|
setResponseStatus(event, 202)
|
|
return 'Successfully logged in.'
|
|
|
|
})
|