1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

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.
This commit is contained in:
Nuno Góis 2023-12-21 12:06:20 +00:00 committed by GitHub
parent 60d3768ab1
commit efa691d120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,3 +7,10 @@ export function extractUsernameFromUser(user: IUser): string {
export function extractUsername(req: IAuthRequest): string { export function extractUsername(req: IAuthRequest): string {
return extractUsernameFromUser(req.user); return extractUsernameFromUser(req.user);
} }
export const extractUserId = (req: IAuthRequest) => req.user.id;
export const extractUserInfo = (req: IAuthRequest) => ({
id: extractUserId(req),
username: extractUsername(req),
});