Skip to content

Commit 231133e

Browse files
chore: introduce generic request to be able to handle different kind of requests
1 parent e5d35f2 commit 231133e

32 files changed

+3608
-547
lines changed

src/server/auth-client.test.ts

Lines changed: 541 additions & 91 deletions
Large diffs are not rendered by default.

src/server/auth-client.ts

Lines changed: 280 additions & 166 deletions
Large diffs are not rendered by default.

src/server/base-path-logout-integration.test.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { RequestCookies, ResponseCookies } from "@edge-runtime/cookies";
22
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33

44
import { Auth0Client } from "./client.js";
5-
import { deleteChunkedCookie, deleteCookie } from "./cookies.js";
5+
import { deleteChunkedCookie } from "./cookies.js";
66
import { StatelessSessionStore } from "./session/stateless-session-store.js";
77
import { TransactionStore } from "./transaction-store.js";
8+
import { Auth0RequestCookies, Auth0ResponseCookies } from "./http/index.js";
89

910
describe("Base path and cookie configuration tests", () => {
1011
let originalEnv: NodeJS.ProcessEnv;
@@ -55,7 +56,7 @@ describe("Base path and cookie configuration tests", () => {
5556
mockReqCookies.getAll = () => [];
5657

5758
// Call delete method (this would be called during logout)
58-
await sessionStore.delete(mockReqCookies, mockResCookies);
59+
await sessionStore.delete(new Auth0RequestCookies(mockReqCookies), new Auth0ResponseCookies(mockResCookies));
5960

6061
// Verify that the cookie deletion header includes the correct path
6162
const cookieHeader = mockResCookies.toString();
@@ -90,7 +91,7 @@ describe("Base path and cookie configuration tests", () => {
9091
mockReqCookies.get = () => ({ value: "mock-session-value" });
9192
mockReqCookies.getAll = () => [];
9293

93-
await sessionStore.delete(mockReqCookies, mockResCookies);
94+
await sessionStore.delete(new Auth0RequestCookies(mockReqCookies), new Auth0ResponseCookies(mockResCookies));
9495

9596
const cookieHeader = mockResCookies.toString();
9697

@@ -132,7 +133,8 @@ describe("Base path and cookie configuration tests", () => {
132133
});
133134

134135
it("should delete cookie with default path when no path is specified", () => {
135-
deleteCookie(mockResCookies, "test-cookie");
136+
const auth0ResCookies = new Auth0ResponseCookies(mockResCookies);
137+
auth0ResCookies.delete("test-cookie");
136138

137139
const cookieHeader = mockResCookies.toString();
138140
expect(cookieHeader).toContain("test-cookie=");
@@ -141,7 +143,11 @@ describe("Base path and cookie configuration tests", () => {
141143
});
142144

143145
it("should delete cookie with specified path", () => {
144-
deleteCookie(mockResCookies, "test-cookie", { path: "/dashboard" });
146+
const auth0ResCookies = new Auth0ResponseCookies(mockResCookies);
147+
auth0ResCookies.delete({
148+
name: "test-cookie",
149+
path: "/dashboard"
150+
});
145151

146152
const cookieHeader = mockResCookies.toString();
147153
expect(cookieHeader).toContain("test-cookie=");
@@ -150,7 +156,11 @@ describe("Base path and cookie configuration tests", () => {
150156
});
151157

152158
it("should delete cookie with root path explicitly", () => {
153-
deleteCookie(mockResCookies, "test-cookie", { path: "/" });
159+
const auth0ResCookies = new Auth0ResponseCookies(mockResCookies);
160+
auth0ResCookies.delete({
161+
name: "test-cookie",
162+
path: "/"
163+
});
154164

155165
const cookieHeader = mockResCookies.toString();
156166
expect(cookieHeader).toContain("test-cookie=");
@@ -168,8 +178,8 @@ describe("Base path and cookie configuration tests", () => {
168178

169179
deleteChunkedCookie(
170180
"test-cookie",
171-
mockReqCookies,
172-
mockResCookies,
181+
new Auth0RequestCookies(mockReqCookies),
182+
new Auth0ResponseCookies(mockResCookies),
173183
false,
174184
{ path: "/dashboard" }
175185
);
@@ -284,7 +294,7 @@ describe("Base path and cookie configuration tests", () => {
284294
}
285295
});
286296

287-
await sessionStore.delete(mockReqCookies, mockResCookies);
297+
await sessionStore.delete(new Auth0RequestCookies(mockReqCookies), new Auth0ResponseCookies(mockResCookies));
288298

289299
const cookieHeader = mockResCookies.toString();
290300
expect(cookieHeader).toContain("__session=");
@@ -304,7 +314,7 @@ describe("Base path and cookie configuration tests", () => {
304314
}
305315
});
306316

307-
await transactionStore.delete(mockResCookies, "test-state");
317+
await transactionStore.delete(new Auth0ResponseCookies(mockResCookies), "test-state");
308318

309319
const cookieHeader = mockResCookies.toString();
310320
expect(cookieHeader).toContain("__txn_test-state=");
@@ -330,7 +340,7 @@ describe("Base path and cookie configuration tests", () => {
330340
}
331341
});
332342

333-
await transactionStore.deleteAll(mockReqCookies, mockResCookies);
343+
await transactionStore.deleteAll(new Auth0RequestCookies(mockReqCookies), new Auth0ResponseCookies(mockResCookies));
334344

335345
const cookieHeader = mockResCookies.toString();
336346
expect(cookieHeader).toContain("__txn_state1=");
@@ -373,7 +383,9 @@ describe("Base path and cookie configuration tests", () => {
373383
});
374384

375385
it("should handle empty path correctly", () => {
376-
deleteCookie(new ResponseCookies(new Headers()), "test-cookie", {
386+
const auth0ResponseCookies = new Auth0ResponseCookies(new ResponseCookies(new Headers()));
387+
auth0ResponseCookies.delete({
388+
name: "test-cookie",
377389
path: ""
378390
});
379391

src/server/beforeSessionSaved-token-refresh-flow.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextRequest } from "next/server.js";
1+
import { NextRequest, NextResponse } from "next/server.js";
22
import * as jose from "jose";
33
import { http, HttpResponse } from "msw";
44
import { setupServer } from "msw/node";
@@ -8,6 +8,7 @@ import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
88
import { getDefaultRoutes } from "../test/defaults.js";
99
import { generateSecret } from "../test/utils.js";
1010
import { SessionData } from "../types/index.js";
11+
import { Auth0NextRequest, Auth0NextResponse } from "./http/index.js";
1112
import { AuthClient } from "./auth-client.js";
1213
import { decrypt, encrypt } from "./cookies.js";
1314
import { StatelessSessionStore } from "./session/stateless-session-store.js";
@@ -217,7 +218,13 @@ describe("AuthClient - beforeSessionSaved hook", async () => {
217218
headers
218219
});
219220

220-
const response = await authClient.handleAccessToken(request);
221+
const auth0Req = new Auth0NextRequest(request);
222+
223+
const auth0Res = new Auth0NextResponse(NextResponse.next());
224+
225+
await authClient.handleAccessToken(auth0Req, auth0Res);
226+
227+
const response = auth0Res.res;
221228

222229
// Verify the response
223230
expect(response.status).toEqual(200);

0 commit comments

Comments
 (0)