diff --git a/.eslintrc b/.eslintrc index 879d41e7..5bee3300 100644 --- a/.eslintrc +++ b/.eslintrc @@ -22,8 +22,7 @@ "rules": { "@typescript-eslint/no-floating-promises": "off", "no-duplicate-imports": "off", - "no-extra-parens": "off", - "@typescript-eslint/dot-notation": "off" + "no-extra-parens": "off" } }, { diff --git a/src/lib/http/middleware/authenticate.ts b/src/lib/http/middleware/authenticate.ts index 060adba5..da21f707 100644 --- a/src/lib/http/middleware/authenticate.ts +++ b/src/lib/http/middleware/authenticate.ts @@ -21,7 +21,7 @@ export const authenticate: ExtendedMiddleware = async (ctx, next) => { return; } - ctx.state['userId'] = userId; + ctx.state.userId = userId; } return next(); diff --git a/src/lib/rate-limiter.ts b/src/lib/rate-limiter.ts index c47c407b..deabd8b5 100644 --- a/src/lib/rate-limiter.ts +++ b/src/lib/rate-limiter.ts @@ -30,9 +30,9 @@ export const rateLimit = async (ctx: ExtendedContext, numberOfProbes: number) => let rateLimiter: RateLimiterRedis; let id: string; - if (ctx.state['userId']) { + if (ctx.state.userId) { rateLimiter = authenticatedRateLimiter; - id = ctx.state['userId'] as string; + id = ctx.state.userId; } else { rateLimiter = anonymousRateLimiter; id = requestIp.getClientIp(ctx.req) ?? ''; diff --git a/src/types.d.ts b/src/types.d.ts index 0573b54b..0a804c86 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -2,7 +2,7 @@ import type Koa from 'koa'; import type Router from '@koa/router'; import type { DocsLinkContext } from './lib/http/middleware/docs-link.js'; -export type CustomState = Koa.DefaultState; +export type CustomState = Koa.DefaultState & { userId?: string }; export type CustomContext = Koa.DefaultContext & DocsLinkContext; export type ExtendedContext = Router.RouterContext;