Files
exams/backend/src/routes/account/fetch.ts
Space-Banane ead561d10b first commit
2026-02-09 19:26:40 +01:00

29 lines
813 B
TypeScript

import { COOKIENAME } from "../..";
import { db, fileRouter } from "../../";
import { authCheck } from "../../lib/Auth";
export = new fileRouter.Path("/").http("GET", "/api/account/fetch", (http) =>
http.onRequest(async (ctr) => {
const cookie = ctr.cookies.get(COOKIENAME) || null;
const apiHeader = (ctr.headers && ctr.headers.get)
? ctr.headers.get("api-authentication") || null
: null;
const auth = await authCheck(cookie, apiHeader);
if (!auth.state) {
return ctr
.status(ctr.$status.UNAUTHORIZED)
.print({ error: auth.message });
}
// Return user data without sensitive information
return ctr.print({
success: true,
user: {
...auth.user,
passwordHash: undefined, // nukes sensitive info
},
});
})
);