diff --git a/src/routes/v1/account.ts b/src/routes/v1/account.ts index 79d674f..be168a4 100644 --- a/src/routes/v1/account.ts +++ b/src/routes/v1/account.ts @@ -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;