fastify-txstate 3.2.6 → 3.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,7 @@ declare class Context<AuthType extends FastifyTxStateAuthInfo = FastifyTxStateAu
29
29
  }>;
30
30
  constructor(req?: FastifyRequest);
31
31
  waitForAuth(): Promise<AuthType | undefined>;
32
+ protected static hasInitialized: boolean;
32
33
  static init(): void;
33
34
  /**
34
35
  * If implemented, this method will be called on startup, once per configured issuer. It receives
@@ -58,5 +59,5 @@ declare class TxStateUAuthContext extends Context {
58
59
  authFromPayload(payload: JWTPayload): Promise<FastifyTxStateAuthInfo>;
59
60
  }
60
61
  export declare function unifiedAuthenticate(req: FastifyRequest, ContextClass?: typeof TxStateUAuthContext): Promise<FastifyTxStateAuthInfo | undefined>;
61
- export declare function unifiedAuthenticateAll(req: FastifyRequest, ContextClass?: typeof TxStateUAuthContext): Promise<FastifyTxStateAuthInfo>;
62
+ export declare function unifiedAuthenticateAll(req: FastifyRequest, ContextClass?: typeof TxStateUAuthContext): Promise<FastifyTxStateAuthInfo | undefined>;
62
63
  export {};
@@ -28,6 +28,9 @@ class Context extends MockContext {
28
28
  }
29
29
  static init() {
30
30
  var _b;
31
+ if (this.hasInitialized)
32
+ return;
33
+ this.hasInitialized = true;
31
34
  let secret = cleanPem(process.env.JWT_SECRET_VERIFY);
32
35
  if (secret != null) {
33
36
  _a.jwtVerifyKey = (0, crypto_1.createPublicKey)(secret);
@@ -102,6 +105,7 @@ Context.tokenCache = new txstate_utils_1.Cache(async (token, { req, ctx }) => {
102
105
  return undefined;
103
106
  }
104
107
  }, { freshseconds: 10 });
108
+ Context.hasInitialized = false;
105
109
  class TxStateUAuthContext extends Context {
106
110
  static processIssuerConfig(config) {
107
111
  var _b;
@@ -132,14 +136,17 @@ class TxStateUAuthContext extends Context {
132
136
  }
133
137
  }
134
138
  async function unifiedAuthenticate(req, ContextClass = TxStateUAuthContext) {
139
+ ContextClass.init();
135
140
  const ctx = new ContextClass(req);
136
141
  return ctx.waitForAuth();
137
142
  }
138
143
  exports.unifiedAuthenticate = unifiedAuthenticate;
139
144
  async function unifiedAuthenticateAll(req, ContextClass = TxStateUAuthContext) {
145
+ var _b;
146
+ ContextClass.init();
140
147
  const ctx = new ContextClass(req);
141
148
  const auth = await ctx.waitForAuth();
142
- if (!(auth === null || auth === void 0 ? void 0 : auth.username.length))
149
+ if (!(auth === null || auth === void 0 ? void 0 : auth.username.length) && !((_b = req.routeOptions.url) === null || _b === void 0 ? void 0 : _b.startsWith('/docs')))
143
150
  throw new Error('All requests require authentication.');
144
151
  return auth;
145
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-txstate",
3
- "version": "3.2.6",
3
+ "version": "3.2.7",
4
4
  "description": "A small wrapper for fastify providing a set of common conventions & utility functions we use.",
5
5
  "exports": {
6
6
  ".": {