Skip to content

Commit eda6c55

Browse files
authored
Merge branch 'main' into feat/custom-profile-and-access-token-routes
2 parents 93448c3 + 4609485 commit eda6c55

6 files changed

Lines changed: 99 additions & 81 deletions

File tree

pnpm-lock.yaml

Lines changed: 68 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/server/client.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,26 @@ ykwV8CV22wKDubrDje1vchfTL/ygX6p27RKpJm8eAH7k3EwVeg3NDfNVzQ==
713713
expect(client["sessionStore"].set).toHaveBeenCalledTimes(1);
714714
});
715715

716+
it("should save session with plain Request and NextResponse", async () => {
717+
vi.spyOn(client["sessionStore"], "set").mockImplementation(
718+
async (_reqCookies, resCookies) => {
719+
resCookies.set("appSession", "updated_session_value");
720+
}
721+
);
722+
723+
const req = new Request("https://myapp.test/api/update", {
724+
method: "POST",
725+
headers: { cookie: "appSession=mock_session_cookie" }
726+
});
727+
const res = NextResponse.next();
728+
729+
await (client as any).saveToSession(mockSession, req as any, res as any);
730+
731+
expect(res.cookies.get("appSession")?.value).toBe(
732+
"updated_session_value"
733+
);
734+
});
735+
716736
it("should create fetcher successfully with plain Request", async () => {
717737
vi.spyOn(client, "getSession").mockResolvedValue(mockSession);
718738

src/server/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,10 @@ export class Auth0Client {
11391139
res?: PagesRouterResponse | NextResponse
11401140
) {
11411141
if (req && res) {
1142-
if (req instanceof NextRequest && res instanceof NextResponse) {
1142+
if (isRequest(req) && res instanceof NextResponse) {
11431143
// middleware usage
1144-
await this.sessionStore.set(req.cookies, res.cookies, data);
1144+
const nextReq = toNextRequest(req);
1145+
await this.sessionStore.set(nextReq.cookies, res.cookies, data);
11451146
} else {
11461147
// pages router usage
11471148
const resHeaders = new Headers();

src/server/cookies.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ describe("encrypt/decrypt", async () => {
3131
const maxAge = 60 * 60; // 1 hour in seconds
3232
const expiration = Math.floor(Date.now() / 1000 + maxAge);
3333
const encrypted = await encrypt(payload, secret, expiration);
34-
await expect(() =>
35-
decrypt(encrypted, incorrectSecret)
36-
).rejects.toThrowError();
34+
const decrypted = await decrypt(encrypted, incorrectSecret);
35+
expect(decrypted).toBeNull();
3736
});
3837

3938
it("should fail to decrypt when expired", async () => {

0 commit comments

Comments
 (0)