Skip to content

Commit

Permalink
fix: allow overriding the query parameter (#1847)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Nov 23, 2024
1 parent 197a05c commit 669b075
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/ui/docs-bundle/src/server/auth/getAuthState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,20 @@ function getAuthorizationUrl(authConfig: AuthEdgeConfig, host: string, pathname?
const state = urlJoin(removeTrailingSlash(withDefaultProtocol(host)), pathname ?? "");

if (authConfig.type === "basic_token_verification") {
const redirectUri = urlJoin(removeTrailingSlash(withDefaultProtocol(host)), "/api/fern-docs/auth/jwt/callback");
const destination = new URL(authConfig.redirect);
destination.searchParams.set("redirect_uri", redirectUri);
destination.searchParams.set(getReturnToQueryParam(authConfig), state);

// note: `redirect` is allowed to override the default redirect uri, and the `return_to` param
if (!destination.searchParams.has("redirect_uri")) {
const redirectUri = urlJoin(
removeTrailingSlash(withDefaultProtocol(host)),
"/api/fern-docs/auth/jwt/callback",
);

destination.searchParams.set("redirect_uri", redirectUri);
}
if (!destination.searchParams.has(getReturnToQueryParam(authConfig))) {
destination.searchParams.set(getReturnToQueryParam(authConfig), state);
}
return destination.toString();
} else if (authConfig.type === "sso" && authConfig.partner === "workos") {
const redirectUri = urlJoin(removeTrailingSlash(withDefaultProtocol(host)), "/api/fern-docs/auth/sso/callback");
Expand Down

0 comments on commit 669b075

Please sign in to comment.