implemented connection to the backend
This commit is contained in:
@ -1,30 +1,14 @@
|
||||
import { globalUserObject } from "../middleware/login";
|
||||
import { loginSuccessful, errorMsg } 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) {
|
||||
if (!loginSuccessful) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Username or password not valid.',
|
||||
statusMessage: errorMsg,
|
||||
})
|
||||
}
|
||||
|
||||
setResponseStatus(event, 202)
|
||||
setResponseStatus(event, 200)
|
||||
return 'Successfully logged in.'
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user