1import { readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff";
2
3let pending: ReturnType<typeof readCodexAuthDelivery>;
4
5/** Remove the code before the router, tracing, or welcome screen sees the incoming address. */
6export function prepareProviderAuthDelivery() {
7 if (!window.location.hash.startsWith("#codex-auth=")) return;
8 pending = readCodexAuthDelivery(window.location.href);
9 window.history.replaceState(
10 window.history.state,
11 "",
12 pending?.returnUrl ?? `${window.location.pathname}${window.location.search}`,
13 );
14}
15
16export const pendingProviderAuthDelivery = () => pending;
17export const clearProviderAuthDelivery = () => {
18 pending = undefined;
19};