@zitadel/sdk-next 0.1.0-alpha.10 → 0.1.0-alpha.12

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/auth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthResult } from '@zitadel/sdk-core/types';
1
+ import { AuthResult } from '@zitadel/sdk-core/middleware';
2
2
 
3
3
  /**
4
4
  * Reads the auth state in a React Server Component or Next.js Route Handler.
package/dist/auth.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  auth
3
- } from "./chunk-B7S6XMT3.js";
4
- import "./chunk-OCZMYSFX.js";
3
+ } from "./chunk-WZU5OYIF.js";
4
+ import "./chunk-KHTLEMQO.js";
5
5
  export {
6
6
  auth
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  base64UrlDecode,
3
3
  verifyJwt
4
- } from "./chunk-OCZMYSFX.js";
4
+ } from "./chunk-KHTLEMQO.js";
5
5
 
6
6
  // src/middleware.ts
7
7
  import {
@@ -35,8 +35,7 @@ async function nextgenMiddleware(req, options = {}) {
35
35
  audience,
36
36
  allowedTokenTypes = ["JWT", "at+JWT"],
37
37
  jwksTimeoutMs,
38
- proxyTimeoutMs = 5e3,
39
- onExchangeResponse
38
+ proxyTimeoutMs = 5e3
40
39
  } = options;
41
40
  if (!loginPath.startsWith("/") || loginPath.startsWith("//")) {
42
41
  throw new Error(
@@ -49,13 +48,7 @@ async function nextgenMiddleware(req, options = {}) {
49
48
  return NextResponse.next({ request: { headers } });
50
49
  }
51
50
  if (pathname === proxyPath || pathname.startsWith(`${proxyPath}/`)) {
52
- return proxyRequest(
53
- req,
54
- url,
55
- proxyPath,
56
- proxyTimeoutMs,
57
- onExchangeResponse
58
- );
51
+ return proxyRequest(req, url, proxyPath, proxyTimeoutMs);
59
52
  }
60
53
  return handleAuth(req, {
61
54
  url,
@@ -74,9 +67,7 @@ function isJwtShaped(token) {
74
67
  const parts = token.split(".");
75
68
  if (parts.length < 3 || !parts[0]) return false;
76
69
  try {
77
- const header = JSON.parse(
78
- DECODER.decode(base64UrlDecode(parts[0]))
79
- );
70
+ const header = JSON.parse(DECODER.decode(base64UrlDecode(parts[0])));
80
71
  return typeof header?.alg === "string" && !("enc" in header);
81
72
  } catch {
82
73
  return false;
@@ -94,7 +85,7 @@ async function validateOpaqueSessionToken(token, issuerUrl, timeoutMs) {
94
85
  return false;
95
86
  }
96
87
  }
97
- async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeResponse) {
88
+ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs) {
98
89
  const url = new URL(req.url);
99
90
  const suffix = url.pathname.slice(proxyPath.length);
100
91
  const target = `${authUrl}${suffix}${url.search}`;
@@ -108,10 +99,7 @@ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeR
108
99
  const directIp = req.ip ?? req.headers.get("x-real-ip");
109
100
  if (directIp) {
110
101
  const existingXff = upstreamHeaders.get("x-forwarded-for");
111
- upstreamHeaders.set(
112
- "x-forwarded-for",
113
- existingXff ? `${existingXff}, ${directIp}` : directIp
114
- );
102
+ upstreamHeaders.set("x-forwarded-for", existingXff ? `${existingXff}, ${directIp}` : directIp);
115
103
  }
116
104
  if (!upstreamHeaders.has("x-forwarded-host")) {
117
105
  upstreamHeaders.set("x-forwarded-host", url.host);
@@ -120,11 +108,10 @@ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeR
120
108
  upstreamHeaders.set("x-forwarded-proto", url.protocol.replace(":", ""));
121
109
  }
122
110
  const hasBody = !["GET", "HEAD"].includes(req.method);
123
- const isExchangeRequest = req.method === "POST" && suffix.startsWith("/sessions/exchange");
124
- if (isExchangeRequest && !upstreamHeaders.has("authorization")) {
125
- const projectId = url.searchParams.get("project_id");
126
- if (projectId) {
127
- upstreamHeaders.set("authorization", `Bearer sk_${projectId}`);
111
+ if (!upstreamHeaders.has("authorization")) {
112
+ const secret = process.env.ZITADEL_PROJECT_SECRET;
113
+ if (secret) {
114
+ upstreamHeaders.set("authorization", `Bearer ${secret}`);
128
115
  }
129
116
  }
130
117
  const bodyBuffer = hasBody ? await req.arrayBuffer() : void 0;
@@ -140,14 +127,10 @@ async function proxyRequest(req, authUrl, proxyPath, proxyTimeoutMs, onExchangeR
140
127
  for (const cookie of setCookies) {
141
128
  responseHeaders.append("set-cookie", cookie);
142
129
  }
143
- let response = new Response(upstream.body, {
130
+ return new Response(upstream.body, {
144
131
  status: upstream.status,
145
132
  headers: responseHeaders
146
133
  });
147
- if (isExchangeRequest && onExchangeResponse) {
148
- response = await onExchangeResponse(response);
149
- }
150
- return response;
151
134
  }
152
135
  async function handleAuth(req, opts) {
153
136
  const {
@@ -178,11 +161,7 @@ async function handleAuth(req, opts) {
178
161
  return NextResponse.next({ request: { headers: tunnelled2 } });
179
162
  }
180
163
  if (!payload && cookieToken && !isJwtShaped(cookieToken)) {
181
- const isValid = await validateOpaqueSessionToken(
182
- cookieToken,
183
- url,
184
- jwksTimeoutMs ?? 5e3
185
- );
164
+ const isValid = await validateOpaqueSessionToken(cookieToken, url, jwksTimeoutMs ?? 5e3);
186
165
  if (isValid) {
187
166
  const tunnelled2 = tunnelHeaders(req, {
188
167
  "x-nextgen-auth-token": cookieToken
@@ -0,0 +1,8 @@
1
+ // src/lib/jwt.ts
2
+ import { JWKS_TTL_MS, base64UrlDecode, decodeJwt, verifyJwt } from "@zitadel/sdk-core/jwt";
3
+
4
+ export {
5
+ base64UrlDecode,
6
+ decodeJwt,
7
+ verifyJwt
8
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  decodeJwt
3
- } from "./chunk-OCZMYSFX.js";
3
+ } from "./chunk-KHTLEMQO.js";
4
4
 
5
5
  // src/auth.ts
6
6
  import { headers } from "next/headers";
package/dist/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { AuthResult, NextgenSession } from '@zitadel/sdk-core/types';
3
+ import { AuthResult, NextgenSession } from '@zitadel/sdk-core/middleware';
4
4
 
5
5
  declare function NextgenProvider({ session, children, }: {
6
6
  session: AuthResult | NextgenSession | null;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/types';
1
+ export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/middleware';
2
2
  export { ProxyHandler, ProxyOptions, createProxy, nextgenMiddleware } from './middleware.js';
3
3
  export { auth } from './auth.js';
4
4
  export { NextgenProvider, useAuthContext } from './context.js';
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createProxy,
3
3
  nextgenMiddleware
4
- } from "./chunk-4KENHIG4.js";
4
+ } from "./chunk-7D5LORRL.js";
5
5
  import {
6
6
  auth
7
- } from "./chunk-B7S6XMT3.js";
8
- import "./chunk-OCZMYSFX.js";
7
+ } from "./chunk-WZU5OYIF.js";
8
+ import "./chunk-KHTLEMQO.js";
9
9
  import "./chunk-6F4PWJZI.js";
10
10
  import {
11
11
  useAuth
@@ -1,5 +1,5 @@
1
1
  import { ZitadelProject } from '@zitadel/api/config';
2
- import { NextgenMiddlewareOptions } from '@zitadel/sdk-core/types';
2
+ import { NextgenMiddlewareOptions } from '@zitadel/sdk-core/middleware';
3
3
  import { NextRequest, NextResponse } from 'next/server';
4
4
 
5
5
  /**
@@ -38,7 +38,7 @@ declare function nextgenMiddleware(req: NextRequest, options?: NextgenMiddleware
38
38
  * `proxyPath` and `url` are omitted because they come from the
39
39
  * {@link ZitadelConfig} passed as the first argument.
40
40
  */
41
- type ProxyOptions = Omit<NextgenMiddlewareOptions, 'proxyPath' | 'url'>;
41
+ type ProxyOptions = Omit<NextgenMiddlewareOptions, "proxyPath" | "url">;
42
42
  /**
43
43
  * A pre-configured middleware handler returned by {@link createProxy}.
44
44
  */
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createProxy,
3
3
  nextgenMiddleware
4
- } from "./chunk-4KENHIG4.js";
5
- import "./chunk-OCZMYSFX.js";
4
+ } from "./chunk-7D5LORRL.js";
5
+ import "./chunk-KHTLEMQO.js";
6
6
  export {
7
7
  createProxy,
8
8
  nextgenMiddleware
package/dist/server.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { auth } from './auth.js';
2
- import '@zitadel/sdk-core/types';
2
+ import '@zitadel/sdk-core/middleware';
package/dist/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  auth
3
- } from "./chunk-B7S6XMT3.js";
4
- import "./chunk-OCZMYSFX.js";
3
+ } from "./chunk-WZU5OYIF.js";
4
+ import "./chunk-KHTLEMQO.js";
5
5
  export {
6
6
  auth
7
7
  };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/types';
1
+ export { AuthResult, AuthState, NextgenMiddlewareOptions, NextgenSession, UnauthState } from '@zitadel/sdk-core/middleware';
2
2
  import '@zitadel/components';
3
3
  import '@zitadel/api/config';
package/dist/useAuth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AuthResult } from '@zitadel/sdk-core/types';
1
+ import { AuthResult } from '@zitadel/sdk-core/middleware';
2
2
 
3
3
  declare function useAuth(): AuthResult;
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zitadel/sdk-next",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.12",
4
4
  "description": "Next.js helpers and mock auth UI for Zitadel",
5
5
  "homepage": "https://github.com/zitadel/nextgen/tree/main/packages/sdk-next#readme",
6
6
  "bugs": {
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "server-only": "^0.0.1",
42
- "@zitadel/api": "0.1.0-alpha.10",
43
- "@zitadel/components": "0.1.0-alpha.10",
44
- "@zitadel/sdk-core": "0.1.0-alpha.10"
42
+ "@zitadel/api": "0.1.0-alpha.12",
43
+ "@zitadel/components": "0.1.0-alpha.12",
44
+ "@zitadel/sdk-core": "0.1.0-alpha.12"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "next": ">=14",
@@ -50,12 +50,10 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@eslint/js": "^9.0.0",
53
- "tsup": "^8.3.5",
54
- "typescript": "^5.7.3",
55
53
  "@eslint/json": "^0.11.0",
56
54
  "@eslint/markdown": "^6.0.0",
57
- "@testing-library/react": "^16.0.0",
58
- "@testing-library/user-event": "^14.0.0",
55
+ "@testing-library/react": "^16.3.2",
56
+ "@testing-library/user-event": "^14.6.1",
59
57
  "@types/react": "^19.2.14",
60
58
  "eslint": "^9.0.0",
61
59
  "eslint-config-prettier": "^10.0.0",
@@ -67,9 +65,11 @@
67
65
  "eslint-plugin-react": "^7.37.0",
68
66
  "eslint-plugin-react-hooks": "^5.0.0",
69
67
  "eslint-plugin-testing-library": "^7.0.0",
70
- "jsdom": "^26.0.0",
68
+ "jsdom": "^29.0.2",
71
69
  "next": "^16.2.4",
72
70
  "prettier": "^3.0.0",
71
+ "tsup": "^8.3.5",
72
+ "typescript": "^5.7.3",
73
73
  "typescript-eslint": "^8.0.0",
74
74
  "vitest": "^3.0.0"
75
75
  },
@@ -1,13 +0,0 @@
1
- // src/lib/jwt.ts
2
- import {
3
- JWKS_TTL_MS,
4
- base64UrlDecode,
5
- decodeJwt,
6
- verifyJwt
7
- } from "@zitadel/sdk-core/jwt";
8
-
9
- export {
10
- base64UrlDecode,
11
- decodeJwt,
12
- verifyJwt
13
- };