Skip to content

Commit

Permalink
fix: add url to state for redirection from SSR (#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava authored Aug 20, 2024
1 parent c0c1f11 commit d1af0d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,12 @@ export function PlaygroundAuthorizationFormCard({
text="Logout"
intent="none"
onClick={() => {
fetch(urlJoin(window.location.origin, "/api/fern-docs/auth/logout"))
const url = new URL(
urlJoin(window.location.origin, "/api/fern-docs/auth/logout"),
);
const state = new URL(window.location.href);
url.searchParams.set("state", state.toString());
fetch(url)
.then(() => {
window.location.reload();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export default async function GET(req: NextRequest): Promise<NextResponse> {
const domain = getXFernHostEdge(req);
const config = await getAuthEdgeConfig(domain);

const res = NextResponse.redirect(req.nextUrl.origin);
const state = req.nextUrl.searchParams.get("state");
const redirectLocation = state ?? req.nextUrl.origin;

const res = NextResponse.redirect(redirectLocation);
if (config != null && config.type === "oauth2" && config.partner === "ory") {
res.cookies.delete("fern_token");
res.cookies.delete("access_token");
Expand Down

0 comments on commit d1af0d2

Please sign in to comment.