Skip to content

Commit

Permalink
fix: store userId in state
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Jan 29, 2024
1 parent e5475d5 commit bc3f44a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"rules": {
"@typescript-eslint/no-floating-promises": "off",
"no-duplicate-imports": "off",
"no-extra-parens": "off"
"no-extra-parens": "off",
"@typescript-eslint/dot-notation": "off"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/http/middleware/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const authenticate = async (ctx: Context, next: Next) => {
return;
}

ctx['auth'] = userId;
ctx.state['userId'] = userId;
}

return next();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rate-limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export const rateLimit = async (ctx: Context, numberOfProbes: number) => {
let rateLimiter: RateLimiterRedis;
let id: string;

if (ctx['auth']) {
if (ctx.state['userId']) {
rateLimiter = authenticatedRateLimiter;
id = ctx['auth'] as string;
id = ctx.state['userId'] as string;
} else {
rateLimiter = anonymousRateLimiter;
id = requestIp.getClientIp(ctx.req) ?? '';
Expand Down

0 comments on commit bc3f44a

Please sign in to comment.