@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.d.ts CHANGED
@@ -86,9 +86,12 @@ type ProxyOptions = {
86
86
  * @typeParam UserClaims - App-specific claims expected on `session.user`.
87
87
  */
88
88
  declare class MondoAuthClient<UserClaims extends Claims = Claims> {
89
- private readonly instance;
89
+ private instance?;
90
+ private readonly configOverrides?;
90
91
  /**
91
- * Creates a client and validates configuration immediately.
92
+ * Creates a client. Configuration is validated lazily the first time it is
93
+ * needed so importing the client is safe before Next.js loads environment
94
+ * files.
92
95
  *
93
96
  * @param config - Optional explicit config. Environment variables provide the
94
97
  * remaining values.
@@ -188,6 +191,7 @@ declare class MondoAuthClient<UserClaims extends Claims = Claims> {
188
191
  * fresh at the request boundary.
189
192
  */
190
193
  proxy: (request: Request, options?: ProxyOptions) => Promise<Response | undefined>;
194
+ private getInstance;
191
195
  }
192
196
  /**
193
197
  * Creates a configured Mondo auth client.
package/dist/client.js CHANGED
@@ -1154,20 +1154,23 @@ function getStatusCode(code) {
1154
1154
  // src/client.ts
1155
1155
  var MondoAuthClient = class {
1156
1156
  instance;
1157
+ configOverrides;
1157
1158
  /**
1158
- * Creates a client and validates configuration immediately.
1159
+ * Creates a client. Configuration is validated lazily the first time it is
1160
+ * needed so importing the client is safe before Next.js loads environment
1161
+ * files.
1159
1162
  *
1160
1163
  * @param config - Optional explicit config. Environment variables provide the
1161
1164
  * remaining values.
1162
1165
  */
1163
1166
  constructor(config) {
1164
- this.instance = initInstance(config);
1167
+ this.configOverrides = config;
1165
1168
  }
1166
1169
  /**
1167
1170
  * Validated auth configuration used by this client.
1168
1171
  */
1169
1172
  get config() {
1170
- return this.instance.config;
1173
+ return this.getInstance().config;
1171
1174
  }
1172
1175
  /**
1173
1176
  * Returns one route handler that serves all configured auth routes.
@@ -1207,31 +1210,31 @@ var MondoAuthClient = class {
1207
1210
  * Creates a route handler that starts the OIDC login redirect.
1208
1211
  */
1209
1212
  handleLogin(options) {
1210
- return loginHandlerFactory(this.instance)(options);
1213
+ return loginHandlerFactory(this.getInstance())(options);
1211
1214
  }
1212
1215
  /**
1213
1216
  * Creates a route handler that completes the OIDC callback.
1214
1217
  */
1215
1218
  handleCallback(options) {
1216
- return callbackHandlerFactory(this.instance)(options);
1219
+ return callbackHandlerFactory(this.getInstance())(options);
1217
1220
  }
1218
1221
  /**
1219
1222
  * Creates a route handler that clears the local session.
1220
1223
  */
1221
1224
  handleLogout(options) {
1222
- return logoutHandlerFactory(this.instance)(options);
1225
+ return logoutHandlerFactory(this.getInstance())(options);
1223
1226
  }
1224
1227
  /**
1225
1228
  * Creates a route handler that returns the current session as JSON.
1226
1229
  */
1227
1230
  handleSession(options) {
1228
- return sessionHandlerFactory(this.instance)(options);
1231
+ return sessionHandlerFactory(this.getInstance())(options);
1229
1232
  }
1230
1233
  /**
1231
1234
  * Creates a route handler that returns or refreshes the current access token.
1232
1235
  */
1233
1236
  handleAccessToken(options) {
1234
- return accessTokenHandlerFactory(this.instance)(options);
1237
+ return accessTokenHandlerFactory(this.getInstance())(options);
1235
1238
  }
1236
1239
  /**
1237
1240
  * Reads the current sealed-cookie session in server code.
@@ -1244,7 +1247,7 @@ var MondoAuthClient = class {
1244
1247
  * when the token is expired or missing required scopes.
1245
1248
  */
1246
1249
  getAccessToken = (options) => {
1247
- return getAccessTokenFactory(this.instance)(options);
1250
+ return getAccessTokenFactory(this.getInstance())(options);
1248
1251
  };
1249
1252
  /**
1250
1253
  * Drop this into `proxy.ts` to protect matched routes and keep idle sessions
@@ -1277,6 +1280,10 @@ var MondoAuthClient = class {
1277
1280
  await sessionStore.touch();
1278
1281
  return response;
1279
1282
  };
1283
+ getInstance() {
1284
+ this.instance ??= initInstance(this.configOverrides);
1285
+ return this.instance;
1286
+ }
1280
1287
  };
1281
1288
  function createAuth(config) {
1282
1289
  return new MondoAuthClient(config);