Skip to content

Commit

Permalink
fix(next): returns correct status for signing in with `redirect: fals…
Browse files Browse the repository at this point in the history
…e` for route handler (#8775)

* fix: returns status for signing in with credentials provider `redirect: false`

* chore: format cookie.ts
  • Loading branch information
ThangHuuVu authored Oct 2, 2023
1 parent 5f15b07 commit 27b2519
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/next-auth/src/core/lib/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function defaultCookies(useSecureCookies: boolean): CookiesOptions {
path: "/",
secure: useSecureCookies,
},
}
},
}
}

Expand Down Expand Up @@ -161,22 +161,22 @@ export class SessionStore {
}
}

/**
/**
* 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")
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
});
return aSuffix - bSuffix
})

// Use the sorted keys to join the chunks in the correct order
return sortedKeys.map(key => this.#chunks[key]).join("")
}
// 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 change: 1 addition & 0 deletions packages/next-auth/src/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async function NextAuthRouteHandler(
response.headers.delete("Location")
response.headers.set("Content-Type", "application/json")
return new Response(JSON.stringify({ url: redirect }), {
status: internalResponse.status,
headers: response.headers,
})
}
Expand Down

1 comment on commit 27b2519

@vercel
Copy link

@vercel vercel bot commented on 27b2519 Oct 2, 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.