@sourceregistry/sveltekit-oidc 1.6.14 → 1.8.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.
- package/README.md +7 -0
- package/dist/server/index.js +14 -8
- package/dist/server/types.d.ts +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -155,6 +155,13 @@ export async function load(event) {
|
|
|
155
155
|
`OIDCContext`, so the standard setup above does not re-run unrelated page loads. If you destructure
|
|
156
156
|
the load event, pass both `cookies` and `depends`: `oidc.getPublicSession({cookies, depends})`.
|
|
157
157
|
|
|
158
|
+
When `oidc.handle` has already loaded an enriched session for the current request, project that
|
|
159
|
+
session without reading or enriching it again:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const session = oidc.toPublicSession(event.locals.oidc?.session ?? null, event.depends);
|
|
163
|
+
```
|
|
164
|
+
|
|
158
165
|
Periodic revalidation is disabled by default to avoid unnecessary page updates. Set
|
|
159
166
|
`revalidateIntervalMs` to a positive interval only when you need polling in addition to token-expiry
|
|
160
167
|
and provider session monitoring. Existing integrations that pass only `cookies` remain compatible;
|
package/dist/server/index.js
CHANGED
|
@@ -356,7 +356,11 @@ export function createOIDC(options) {
|
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
async function getSession(event) {
|
|
359
|
-
|
|
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();
|
|
@@ -614,18 +618,20 @@ export function createOIDC(options) {
|
|
|
614
618
|
backChannelLogoutSessionSupported: Boolean(metadata.backchannel_logout_session_supported)
|
|
615
619
|
};
|
|
616
620
|
}
|
|
621
|
+
function createPublicSession(session, depends) {
|
|
622
|
+
depends?.(OIDC_SESSION_REVALIDATION_DEPENDENCY);
|
|
623
|
+
const publicSession = toPublicSession(session);
|
|
624
|
+
return publicSession && depends
|
|
625
|
+
? { ...publicSession, revalidationDependency: OIDC_SESSION_REVALIDATION_DEPENDENCY }
|
|
626
|
+
: publicSession;
|
|
627
|
+
}
|
|
617
628
|
return {
|
|
618
629
|
handle,
|
|
619
630
|
hook,
|
|
620
631
|
getMetadata,
|
|
621
632
|
getSession,
|
|
622
|
-
getPublicSession: async (event) =>
|
|
623
|
-
|
|
624
|
-
const session = toPublicSession(await getSession(event));
|
|
625
|
-
return session && event.depends
|
|
626
|
-
? { ...session, revalidationDependency: OIDC_SESSION_REVALIDATION_DEPENDENCY }
|
|
627
|
-
: session;
|
|
628
|
-
},
|
|
633
|
+
getPublicSession: async (event) => createPublicSession(await getSession(event), event.depends),
|
|
634
|
+
toPublicSession: createPublicSession,
|
|
629
635
|
getSessionManagementConfig,
|
|
630
636
|
login: signIn,
|
|
631
637
|
logout: signOut,
|
package/dist/server/types.d.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -278,6 +290,8 @@ export type OIDCInstance<TClaims extends OIDCUserClaims = OIDCUserClaims, TSessi
|
|
|
278
290
|
cookies: Cookies;
|
|
279
291
|
depends?: (dependency: string) => void;
|
|
280
292
|
}) => Promise<OIDCPublicSession<TClaims> | null>;
|
|
293
|
+
/** Projects an already-loaded session without reading, refreshing, or enriching it again. */
|
|
294
|
+
toPublicSession: (session: TSession | null, depends?: (dependency: string) => void) => OIDCPublicSession<TClaims> | null;
|
|
281
295
|
getSessionManagementConfig: () => Promise<OIDCSessionManagementConfig>;
|
|
282
296
|
login: (event: MinimalRequestEvent, loginOptions?: OIDCLoginOptions) => Promise<never>;
|
|
283
297
|
logout: (event: MinimalRequestEvent, logoutOptions?: OIDCLogoutOptions) => Promise<never>;
|