From efa691d120389dfac597a51b81586f6e55728caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Thu, 21 Dec 2023 12:06:20 +0000 Subject: [PATCH] chore: helper methods to extract user data from req (#5710) With the recent changes it's common that we'll need both the id and processed username from the auth user in the request, so this PR provides some helper methods to simplify this. --- src/lib/util/extract-user.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/util/extract-user.ts b/src/lib/util/extract-user.ts index 84ba126ce5..d58e8d8946 100644 --- a/src/lib/util/extract-user.ts +++ b/src/lib/util/extract-user.ts @@ -7,3 +7,10 @@ export function extractUsernameFromUser(user: IUser): string { export function extractUsername(req: IAuthRequest): string { return extractUsernameFromUser(req.user); } + +export const extractUserId = (req: IAuthRequest) => req.user.id; + +export const extractUserInfo = (req: IAuthRequest) => ({ + id: extractUserId(req), + username: extractUsername(req), +});