From 09d8f670f54691cfa3e29591cf07981ff5a331b2 Mon Sep 17 00:00:00 2001 From: rijkvanzanten Date: Mon, 19 Oct 2020 11:18:58 -0400 Subject: [PATCH] Return user id as minimum data in /users/me --- api/src/controllers/users.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/src/controllers/users.ts b/api/src/controllers/users.ts index 2e0888141e..b3b7ce4eb1 100644 --- a/api/src/controllers/users.ts +++ b/api/src/controllers/users.ts @@ -58,11 +58,21 @@ router.get( if (!req.accountability?.user) { throw new InvalidCredentialsException(); } + const service = new UsersService({ accountability: req.accountability }); - const item = await service.readByKey(req.accountability.user, req.sanitizedQuery); + try { + const item = await service.readByKey(req.accountability.user, req.sanitizedQuery); + res.locals.payload = { data: item || null }; + } catch (error) { + if (error instanceof ForbiddenException) { + res.locals.payload = { data: { id: req.accountability.user } }; + return next(); + } + + throw error; + } - res.locals.payload = { data: item || null }; return next(); }), respond