| 1 | import { readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff"; |
| 2 | |
| 3 | let pending: ReturnType<typeof readCodexAuthDelivery>; |
| 4 | |
| 5 | /** Remove the code before the router, tracing, or welcome screen sees the incoming address. */ |
| 6 | export 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 | |
| 16 | export const pendingProviderAuthDelivery = () => pending; |
| 17 | export const clearProviderAuthDelivery = () => { |
| 18 | pending = undefined; |
| 19 | }; |