first commit
This commit is contained in:
28
backend/src/routes/account/fetch.ts
Normal file
28
backend/src/routes/account/fetch.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
},
|
||||
});
|
||||
})
|
||||
);
|
||||
Reference in New Issue
Block a user