Skip to content
Myr

fix(bearer-auth): mention verifyToken in missing-options error message (#4987)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by MD Tanvirul Islam Niloy · committed by GitHub · parent 2cbeadd · Browse files · 2 files+10 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: tan7vir <tan7vir@users.noreply.github.com>

Diff stats

2 files+10 added−1 removed

  • tests:+9 added−0 removed
  • other:+1 added−1 removed

2 files+10 added−1 removed

modified:src/middleware/bearer-auth/index.test.ts+9 added
1005 unmodified lines
1006 })1007 expectTypeOf(middleware).toEqualTypeOf<MiddlewareHandler<TestEnv>>()1008 })1009})10101011describe('Bearer Auth options validation', () => {1012 it('Should throw an error mentioning both "token" and "verifyToken" when neither is provided', () => {1013 expect(() => {1014 // @ts-expect-error testing runtime guard with no valid options1015 bearerAuth({})1016 }).toThrow('bearer auth middleware requires options for "token" or "verifyToken"')1017 })1018})
modified:src/middleware/bearer-auth/index.ts+1 added-1 removed
103 unmodified lines
104export const bearerAuth = <E extends Env = Env>(105 options: BearerAuthOptions<E>106): MiddlewareHandler<E> => {107 if (!('token' in options || 'verifyToken' in options)) {108 throw new Error('bearer auth middleware requires options for "token"')108 throw new Error('bearer auth middleware requires options for "token" or "verifyToken"')109 }110 if (!options.realm) {111 options.realm = ''112 }
109 unmodified lines