@sourceregistry/sveltekit-oidc 1.4.0 → 1.5.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 +17 -26
- package/dist/client/context.d.ts +7 -3
- package/dist/client/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,14 +12,14 @@ OIDC authentication helpers for SvelteKit with:
|
|
|
12
12
|
## Install
|
|
13
13
|
|
|
14
14
|
```sh
|
|
15
|
-
npm install sveltekit-oidc
|
|
15
|
+
npm install @sourceregistry/sveltekit-oidc
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Server Setup
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
21
|
// src/lib/server/auth.ts
|
|
22
|
-
import { createOIDC } from 'sveltekit-oidc/server';
|
|
22
|
+
import { createOIDC } from '@sourceregistry/sveltekit-oidc/server';
|
|
23
23
|
|
|
24
24
|
export const oidc = createOIDC({
|
|
25
25
|
issuer: 'https://your-idp.example.com',
|
|
@@ -104,7 +104,7 @@ export async function load(event) {
|
|
|
104
104
|
|
|
105
105
|
```html
|
|
106
106
|
<script lang="ts">
|
|
107
|
-
import { OIDCContext } from 'sveltekit-oidc';
|
|
107
|
+
import { OIDCContext } from '@sourceregistry/sveltekit-oidc';
|
|
108
108
|
let { data } = $props();
|
|
109
109
|
</script>
|
|
110
110
|
|
|
@@ -122,7 +122,7 @@ export async function load(event) {
|
|
|
122
122
|
```html
|
|
123
123
|
<!-- src/lib/Account.svelte -->
|
|
124
124
|
<script lang="ts">
|
|
125
|
-
import { useOIDC } from 'sveltekit-oidc';
|
|
125
|
+
import { useOIDC } from '@sourceregistry/sveltekit-oidc';
|
|
126
126
|
|
|
127
127
|
const oidc = useOIDC();
|
|
128
128
|
</script>
|
|
@@ -170,7 +170,7 @@ Wire `App.Locals` so `event.locals.oidc` is fully typed everywhere — `OIDCLoca
|
|
|
170
170
|
|
|
171
171
|
```ts
|
|
172
172
|
// src/app.d.ts
|
|
173
|
-
import type { OIDCLocals } from 'sveltekit-oidc/server';
|
|
173
|
+
import type { OIDCLocals } from '@sourceregistry/sveltekit-oidc/server';
|
|
174
174
|
import { oidc } from '$lib/server/auth';
|
|
175
175
|
|
|
176
176
|
declare global {
|
|
@@ -186,21 +186,12 @@ export {};
|
|
|
186
186
|
|
|
187
187
|
Now `event.locals.oidc?.claims?.roles` is `string[]` and `?.tenant` is `string | undefined` in every hook, load function, and action — no separate type aliases needed.
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
```ts
|
|
192
|
-
import type { OIDCInferClaims } from 'sveltekit-oidc/server';
|
|
193
|
-
import { oidc } from '$lib/server/auth';
|
|
194
|
-
|
|
195
|
-
type AppClaims = OIDCInferClaims<typeof oidc>;
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
`OIDCContext` is a generic component, but Svelte doesn't support passing explicit type arguments in markup — `TClaims` is inferred from the `session` prop instead. Since `data.session` comes from `oidc.getPublicSession(event)`, it's already typed `OIDCPublicSession<AppClaims> | null`, so the inference flows through automatically:
|
|
189
|
+
`OIDCContext` is a generic component, but Svelte doesn't support passing explicit type arguments in markup — `TClaims` is inferred from the `session` prop instead. Since `data.session` comes from `oidc.getPublicSession(event)`, the type flows through automatically:
|
|
199
190
|
|
|
200
191
|
```html
|
|
201
192
|
<!-- src/routes/+layout.svelte -->
|
|
202
193
|
<script lang="ts">
|
|
203
|
-
import { OIDCContext } from 'sveltekit-oidc';
|
|
194
|
+
import { OIDCContext } from '@sourceregistry/sveltekit-oidc';
|
|
204
195
|
let { data, children } = $props();
|
|
205
196
|
</script>
|
|
206
197
|
|
|
@@ -212,14 +203,13 @@ type AppClaims = OIDCInferClaims<typeof oidc>;
|
|
|
212
203
|
```html
|
|
213
204
|
<!-- src/lib/Account.svelte -->
|
|
214
205
|
<script lang="ts">
|
|
215
|
-
import { useOIDC } from 'sveltekit-oidc';
|
|
216
|
-
import type { AppClaims } from '../../app.d.ts';
|
|
206
|
+
import { useOIDC } from '@sourceregistry/sveltekit-oidc';
|
|
217
207
|
|
|
218
|
-
const
|
|
208
|
+
const auth = useOIDC(); // TClaims inferred from App.Locals.oidc
|
|
219
209
|
</script>
|
|
220
210
|
|
|
221
|
-
{#if
|
|
222
|
-
<p>Roles: {
|
|
211
|
+
{#if auth.isAuthenticated}
|
|
212
|
+
<p>Roles: {auth.claims?.roles.join(', ')}</p>
|
|
223
213
|
{/if}
|
|
224
214
|
```
|
|
225
215
|
|
|
@@ -231,8 +221,9 @@ Backend apps commonly stash application-specific data on the session itself (e.g
|
|
|
231
221
|
|
|
232
222
|
```ts
|
|
233
223
|
// src/lib/server/auth.ts
|
|
234
|
-
import { createOIDC, type OIDCSession } from 'sveltekit-oidc/server';
|
|
224
|
+
import { createOIDC, type OIDCSession, type OIDCUserClaims } from '@sourceregistry/sveltekit-oidc/server';
|
|
235
225
|
|
|
226
|
+
type AppClaims = OIDCUserClaims & { tenant?: string };
|
|
236
227
|
type AppSession = OIDCSession<AppClaims> & {
|
|
237
228
|
tenantId: string;
|
|
238
229
|
permissions: string[];
|
|
@@ -255,7 +246,7 @@ export const oidc = createOIDC({
|
|
|
255
246
|
|
|
256
247
|
```ts
|
|
257
248
|
// src/app.d.ts
|
|
258
|
-
import type { OIDCLocals } from 'sveltekit-oidc/server';
|
|
249
|
+
import type { OIDCLocals } from '@sourceregistry/sveltekit-oidc/server';
|
|
259
250
|
import { oidc } from '$lib/server/auth';
|
|
260
251
|
|
|
261
252
|
declare global {
|
|
@@ -271,11 +262,11 @@ export {};
|
|
|
271
262
|
|
|
272
263
|
Now `event.locals.oidc?.session?.tenantId` is `string` and `?.permissions` is `string[]` everywhere — and `oidc.requireAuth(event)` / `handleCallback`'s `onsuccess` resolve to `AppSession` directly.
|
|
273
264
|
|
|
274
|
-
Use `OIDCInferClaims` / `OIDCInferSession` when you need the types explicitly:
|
|
265
|
+
Use `OIDCInferClaims` / `OIDCInferSession` when you need the types explicitly in non-Svelte code (utility functions, API helpers, etc.):
|
|
275
266
|
|
|
276
267
|
```ts
|
|
277
|
-
import type { OIDCInferClaims, OIDCInferSession } from 'sveltekit-oidc/server';
|
|
278
|
-
import { oidc } from '$lib/server/auth';
|
|
268
|
+
import type { OIDCInferClaims, OIDCInferSession } from '@sourceregistry/sveltekit-oidc/server';
|
|
269
|
+
import type { oidc } from '$lib/server/auth';
|
|
279
270
|
|
|
280
271
|
type AppClaims = OIDCInferClaims<typeof oidc>;
|
|
281
272
|
type AppSession = OIDCInferSession<typeof oidc>;
|
package/dist/client/context.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type { OIDCDiscoveryDocument, OIDCPublicSession, OIDCUserClaims } from '../server/index.js';
|
|
1
|
+
import type { OIDCDiscoveryDocument, OIDCHandleLocals, OIDCPublicSession, OIDCUserClaims } from '../server/index.js';
|
|
2
|
+
type LocalsClaims = App.Locals extends {
|
|
3
|
+
oidc?: OIDCHandleLocals<infer C, any>;
|
|
4
|
+
} ? C : OIDCUserClaims;
|
|
2
5
|
export type OIDCClientContextValue<TClaims extends OIDCUserClaims = OIDCUserClaims> = {
|
|
3
6
|
isAuthenticated: boolean;
|
|
4
7
|
session: OIDCPublicSession<TClaims> | null;
|
|
@@ -12,5 +15,6 @@ export type OIDCClientContextValue<TClaims extends OIDCUserClaims = OIDCUserClai
|
|
|
12
15
|
revalidate: () => Promise<void>;
|
|
13
16
|
};
|
|
14
17
|
export declare function setOIDCContext<TClaims extends OIDCUserClaims = OIDCUserClaims>(value: OIDCClientContextValue<TClaims>): OIDCClientContextValue<TClaims>;
|
|
15
|
-
export declare function getOIDCContext<TClaims extends OIDCUserClaims =
|
|
16
|
-
export declare function useOIDC<TClaims extends OIDCUserClaims =
|
|
18
|
+
export declare function getOIDCContext<TClaims extends OIDCUserClaims = LocalsClaims>(): OIDCClientContextValue<TClaims>;
|
|
19
|
+
export declare function useOIDC<TClaims extends OIDCUserClaims = LocalsClaims>(): OIDCClientContextValue<TClaims>;
|
|
20
|
+
export {};
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default as OIDCContext } from './OIDCContext.svelte';
|
|
2
2
|
export { getOIDCContext, useOIDC } from './context.js';
|
|
3
|
-
export type { OIDCPublicSession, OIDCSessionManagementConfig, OIDCUserClaims } from '../server/index.js';
|
|
3
|
+
export type { OIDCInferClaims, OIDCInferSession, OIDCLocals, OIDCPublicSession, OIDCSessionManagementConfig, OIDCUserClaims } from '../server/index.js';
|