@nekm/svelte-core 1.7.12 → 1.7.15

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.
@@ -1,4 +1,5 @@
1
1
  import type { ProtectConfig } from "./contracts.js";
2
+ import { type JWTVerifyGetKey } from "jose";
2
3
  export declare function getRedirectUri(origin: string, path: string): string;
3
- export declare function jwtVerifyIdToken(config: ProtectConfig, jwks: unknown, idToken: string): Promise<import("jose").JWTPayload>;
4
- export declare function jwtVerifyAccessToken(config: ProtectConfig, jwks: unknown, accessToken: string): Promise<import("jose").JWTPayload>;
4
+ export declare function jwtVerifyIdToken(config: ProtectConfig, jwks: JWTVerifyGetKey, idToken: string): Promise<import("jose").JWTPayload>;
5
+ export declare function jwtVerifyAccessToken(config: ProtectConfig, jwks: JWTVerifyGetKey, accessToken: string): Promise<import("jose").JWTPayload>;
@@ -3,18 +3,16 @@ import { jwtVerify } from "jose";
3
3
  export function getRedirectUri(origin, path) {
4
4
  return `${strTrimEnd(origin, "/")}/${path}`;
5
5
  }
6
- export async function jwtVerifyIdToken(config, jwks, idToken) {
7
- const { payload } = await jwtVerify(idToken,
8
- // @ts-expect-error It's OK.
9
- jwks, {
6
+ export function jwtVerifyIdToken(config, jwks, idToken) {
7
+ return jwtVerifyToken(jwks, {
10
8
  issuer: config.oauth.issuer,
11
9
  audience: config.oauth.clientId,
12
- });
13
- return payload;
10
+ }, idToken);
11
+ }
12
+ export function jwtVerifyAccessToken(config, jwks, accessToken) {
13
+ return jwtVerifyToken(jwks, { issuer: config.oauth.issuer }, accessToken);
14
14
  }
15
- export async function jwtVerifyAccessToken(config, jwks, accessToken) {
16
- const { payload } = await jwtVerify(accessToken,
17
- // @ts-expect-error It's OK.
18
- jwks, { issuer: config.oauth.issuer });
15
+ async function jwtVerifyToken(jwks, options, token) {
16
+ const { payload } = await jwtVerify(token, jwks, options);
19
17
  return payload;
20
18
  }
@@ -20,13 +20,16 @@ export const routeRedirectLoginFactory = (config) => {
20
20
  redirect_uri: getRedirectUri(origin, ROUTE_PATH_REDIRECT_LOGIN),
21
21
  }).toString(),
22
22
  });
23
+ if (!response.ok) {
24
+ const error = await response.text();
25
+ throw new Error(`Token exchange failed: ${error}`);
26
+ }
23
27
  return await response.json();
24
28
  }
25
29
  return {
26
30
  path: ROUTE_PATH_REDIRECT_LOGIN,
27
31
  async handle({ event }) {
28
32
  const state = event.url.searchParams.get("state") ?? undefined;
29
- ;
30
33
  const stateSession = await config.session.stateGet(event);
31
34
  if (state !== stateSession) {
32
35
  throw new Error("State do not match");
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@nekm/svelte-core",
3
3
  "description": "Code I find myself re-writing over-and-over, Svelte edition.",
4
4
  "license": "MIT",
5
- "version": "1.7.12",
5
+ "version": "1.7.15",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
8
8
  "build": "vite build && npm run prepack",