@go-mondo/nextjs-auth 0.2.0 → 0.2.1

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.
package/dist/client.cjs CHANGED
@@ -1176,20 +1176,23 @@ function getStatusCode(code) {
1176
1176
  // src/client.ts
1177
1177
  var MondoAuthClient = class {
1178
1178
  instance;
1179
+ configOverrides;
1179
1180
  /**
1180
- * Creates a client and validates configuration immediately.
1181
+ * Creates a client. Configuration is validated lazily the first time it is
1182
+ * needed so importing the client is safe before Next.js loads environment
1183
+ * files.
1181
1184
  *
1182
1185
  * @param config - Optional explicit config. Environment variables provide the
1183
1186
  * remaining values.
1184
1187
  */
1185
1188
  constructor(config) {
1186
- this.instance = initInstance(config);
1189
+ this.configOverrides = config;
1187
1190
  }
1188
1191
  /**
1189
1192
  * Validated auth configuration used by this client.
1190
1193
  */
1191
1194
  get config() {
1192
- return this.instance.config;
1195
+ return this.getInstance().config;
1193
1196
  }
1194
1197
  /**
1195
1198
  * Returns one route handler that serves all configured auth routes.
@@ -1229,31 +1232,31 @@ var MondoAuthClient = class {
1229
1232
  * Creates a route handler that starts the OIDC login redirect.
1230
1233
  */
1231
1234
  handleLogin(options) {
1232
- return loginHandlerFactory(this.instance)(options);
1235
+ return loginHandlerFactory(this.getInstance())(options);
1233
1236
  }
1234
1237
  /**
1235
1238
  * Creates a route handler that completes the OIDC callback.
1236
1239
  */
1237
1240
  handleCallback(options) {
1238
- return callbackHandlerFactory(this.instance)(options);
1241
+ return callbackHandlerFactory(this.getInstance())(options);
1239
1242
  }
1240
1243
  /**
1241
1244
  * Creates a route handler that clears the local session.
1242
1245
  */
1243
1246
  handleLogout(options) {
1244
- return logoutHandlerFactory(this.instance)(options);
1247
+ return logoutHandlerFactory(this.getInstance())(options);
1245
1248
  }
1246
1249
  /**
1247
1250
  * Creates a route handler that returns the current session as JSON.
1248
1251
  */
1249
1252
  handleSession(options) {
1250
- return sessionHandlerFactory(this.instance)(options);
1253
+ return sessionHandlerFactory(this.getInstance())(options);
1251
1254
  }
1252
1255
  /**
1253
1256
  * Creates a route handler that returns or refreshes the current access token.
1254
1257
  */
1255
1258
  handleAccessToken(options) {
1256
- return accessTokenHandlerFactory(this.instance)(options);
1259
+ return accessTokenHandlerFactory(this.getInstance())(options);
1257
1260
  }
1258
1261
  /**
1259
1262
  * Reads the current sealed-cookie session in server code.
@@ -1266,7 +1269,7 @@ var MondoAuthClient = class {
1266
1269
  * when the token is expired or missing required scopes.
1267
1270
  */
1268
1271
  getAccessToken = (options) => {
1269
- return getAccessTokenFactory(this.instance)(options);
1272
+ return getAccessTokenFactory(this.getInstance())(options);
1270
1273
  };
1271
1274
  /**
1272
1275
  * Drop this into `proxy.ts` to protect matched routes and keep idle sessions
@@ -1299,6 +1302,10 @@ var MondoAuthClient = class {
1299
1302
  await sessionStore.touch();
1300
1303
  return response;
1301
1304
  };
1305
+ getInstance() {
1306
+ this.instance ??= initInstance(this.configOverrides);
1307
+ return this.instance;
1308
+ }
1302
1309
  };
1303
1310
  function createAuth(config) {
1304
1311
  return new MondoAuthClient(config);