Address PR review feedback for OIDC sign-in pages
- Remove inline password form from SignInPage (use PasswordSignInPage) - Extract Divider and OIDCButtons to _components folder - Move OIDC providers into page queries instead of lazy-loaded queries - Create useSafeContinueUrl hook for trust app using getPathPrefix - Use safeContinueUrl.toString() for continue URL parameter - Fix wg.Go style in IAM service Run method Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
36
apps/trust/src/hooks/useSafeContinueUrl.ts
Normal file
36
apps/trust/src/hooks/useSafeContinueUrl.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { useMemo } from "react";
|
||||
import { useSearchParams } from "react-router";
|
||||
|
||||
import { getPathPrefix } from "#/utils/pathPrefix";
|
||||
|
||||
export function useSafeContinueUrl(): URL {
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const continueUrlParam = searchParams.get("continue");
|
||||
const prefix = getPathPrefix();
|
||||
const fallback = window.location.origin + (prefix || "/");
|
||||
|
||||
const safeContinueUrl = useMemo(() => {
|
||||
if (continueUrlParam) {
|
||||
let continueUrl: URL;
|
||||
try {
|
||||
continueUrl = new URL(continueUrlParam, window.location.origin);
|
||||
} catch {
|
||||
return new URL(fallback, window.location.origin);
|
||||
}
|
||||
if (
|
||||
continueUrl.origin === window.location.origin
|
||||
&& continueUrl.pathname.startsWith(`${prefix}/`)
|
||||
) {
|
||||
return new URL(
|
||||
continueUrl.pathname + continueUrl.search,
|
||||
window.location.origin,
|
||||
);
|
||||
}
|
||||
return new URL(fallback, window.location.origin);
|
||||
}
|
||||
return new URL(fallback, window.location.origin);
|
||||
}, [continueUrlParam, fallback, prefix]);
|
||||
|
||||
return safeContinueUrl;
|
||||
}
|
||||
Reference in New Issue
Block a user