From 63a728db946d9580484935d2627ba67de742e112 Mon Sep 17 00:00:00 2001 From: Vins Date: Wed, 28 Feb 2024 12:06:26 +0100 Subject: [PATCH] Fixed whitelist --- src/app/api/idnot/UserController.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 6aeabb4b..0521a747 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -25,6 +25,7 @@ export default class UserController extends ApiController { protected async getUserInfosFromIdnot(req: Request, response: Response) { try { const code = req.params["code"]; + if (!code) throw new Error("code is required"); const idNotToken = await this.idNotService.getIdNotToken(code); @@ -34,16 +35,19 @@ export default class UserController extends ApiController { return; } - const user = await this.idNotService.getOrCreateUser(idNotToken); + const user = await this.idNotService.getOrCreateUser(idNotToken); if(!user) { this.httpUnauthorized(response, "Email not found"); return; } + await this.idNotService.updateUser(user.uid); + //Whitelist feature //Get user with contact const prismaUser = await this.userService.getByUid(user.uid, {contact: true }); + if (!prismaUser) { this.httpNotFoundRequest(response, "user not found"); return; @@ -58,15 +62,16 @@ export default class UserController extends ApiController { } //Check if user is whitelisted - const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email); + + const isWhitelisted = await this.whitelistService.getByEmail(userHydrated.contact!.email); //If not whitelisted, return 409 Not whitelisted - if (!isWhitelisted) { + if (!isWhitelisted || isWhitelisted.length === 0) { this.httpNotWhitelisted(response); return; } - await this.idNotService.updateUser(user.uid); + await this.idNotService.updateOffice(user.office_uid); const payload = await this.authService.getUserJwtPayload(user.idNot);