Skip to content

Commit

Permalink
fix: sort cookie chunks correctly (#8284)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenstrom committed Aug 10, 2023
1 parent 124be4f commit 1fbc684
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/next-auth/src/core/lib/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,22 @@ export class SessionStore {
}
}

get value() {
return Object.values(this.#chunks)?.join("")
}
/**
* The JWT Session or database Session ID
* constructed from the cookie chunks.
*/
get value() {
// Sort the chunks by their keys before joining
const sortedKeys = Object.keys(this.#chunks).sort((a, b) => {
const aSuffix = parseInt(a.split(".").pop() || "0")
const bSuffix = parseInt(b.split(".").pop() || "0")

return aSuffix - bSuffix
});

// Use the sorted keys to join the chunks in the correct order
return sortedKeys.map(key => this.#chunks[key]).join("")
}

/** Given a cookie, return a list of cookies, chunked to fit the allowed cookie size. */
#chunk(cookie: Cookie): Cookie[] {
Expand Down

1 comment on commit 1fbc684

@vercel
Copy link

@vercel vercel bot commented on 1fbc684 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.