Added the /user/me route to show information about the logged in user
This commit is contained in:
parent
5f6d41f4b7
commit
91386a158d
@ -1,12 +1,22 @@
|
||||
import { Request, Response, Router } from "express";
|
||||
import { sendError, validateSchema } from "@utils/error";
|
||||
import { registerValidation, totpSetup, verificationValidation } from "./validations/account";
|
||||
import { createAccount, updateTOTP, verifyAccount } from "@controller/account";
|
||||
import { createAccount, generateAvatarUrl, updateTOTP, verifyAccount } from "@controller/account";
|
||||
import { authenticate } from "@middlewares/auth";
|
||||
import speakeasy from "speakeasy";
|
||||
|
||||
const app: Router = Router();
|
||||
|
||||
app.get("/me", authenticate, async (req: Request, res: Response) => {
|
||||
if (!req.user) return sendError(res, 400, 1091, "You are not authenticated.");
|
||||
|
||||
if (!req.user.verified)
|
||||
return sendError(res, 400, 1093, "Your account is not verified. Check your mails to verify.");
|
||||
|
||||
res.json({id: req.user._id, username: req.user.username, email: req.user.email,
|
||||
allowInvites: req.user.allowInvites, totpEnabled: req.user.totpEnabled, avatar: generateAvatarUrl(req.user.email)});
|
||||
});
|
||||
|
||||
app.post("/register", async (req: Request, res: Response) => {
|
||||
if (validateSchema(res, registerValidation, req.body)) return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user