@sourceregistry/sveltekit-oidc 1.6.14 → 1.7.0

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.
@@ -356,7 +356,11 @@ export function createOIDC(options) {
356
356
  }
357
357
  }
358
358
  async function getSession(event) {
359
- return maybeRefreshSession(event.cookies, await readPersistedSession(event.cookies));
359
+ const session = await maybeRefreshSession(event.cookies, await readPersistedSession(event.cookies));
360
+ if (!session || !options.enrichSession) {
361
+ return session;
362
+ }
363
+ return options.enrichSession(session, { event: event });
360
364
  }
361
365
  async function signIn(event, loginOptions = {}) {
362
366
  const metadata = await getMetadata();
@@ -182,6 +182,18 @@ export type OIDCOptions<TClaims extends OIDCUserClaims = OIDCUserClaims, TSessio
182
182
  user?: TClaims;
183
183
  isRefresh: boolean;
184
184
  }) => MaybePromise<TSession>;
185
+ /**
186
+ * Runs on every `getSession` read (and therefore every `getPublicSession`,
187
+ * `hook()`-provided `requireAuth`, and the instance-level `requireAuth`) —
188
+ * unlike `transformSession`, which only fires on session creation and token
189
+ * refresh. Use this to keep data your app owns outside the token (e.g. roles
190
+ * or memberships stored in your own database) fresh without waiting for a
191
+ * refresh. Only invoked when a session is present; the result is not persisted
192
+ * back to the session store.
193
+ */
194
+ enrichSession?: (session: TSession, context: {
195
+ event?: MinimalRequestEvent;
196
+ }) => MaybePromise<TSession>;
185
197
  endpoints?: Partial<OIDCDiscoveryDocument>;
186
198
  logger?: OIDCLogger | false;
187
199
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sourceregistry/sveltekit-oidc",
3
- "version": "1.6.14",
3
+ "version": "1.7.0",
4
4
  "description": "OIDC authentication helpers for SvelteKit applications",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {