Skip to content

Commit

Permalink
chore: helper methods to extract user data from req (#5710)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nunogois committed Dec 21, 2023
1 parent 60d3768 commit efa691d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/util/extract-user.ts
Expand Up @@ -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),
});

0 comments on commit efa691d

Please sign in to comment.