()
| 58 | * localStorage. Identical in dev and prod. |
| 59 | */ |
| 60 | export const bootstrapLocalAuthToken = (): void => { |
| 61 | const url = globalThis.window ? new URL(window.location.href) : null; |
| 62 | const fromUrl = url?.searchParams.get("_token") ?? null; |
| 63 | const stripCacheBust = url?.searchParams.has(DESKTOP_LAUNCH_CACHE_BUST_PARAM) ?? false; |
| 64 | if (stripCacheBust) { |
| 65 | url!.searchParams.delete(DESKTOP_LAUNCH_CACHE_BUST_PARAM); |
| 66 | } |
| 67 | |
| 68 | if (isDesktopBridge()) { |
| 69 | if (fromUrl) { |
| 70 | url!.searchParams.delete("_token"); |
| 71 | } |
| 72 | if (stripCacheBust || fromUrl) { |
| 73 | globalThis.window?.history?.replaceState(null, "", url!.pathname + url!.search + url!.hash); |
| 74 | } |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | if (fromUrl) { |
| 79 | persistToken(fromUrl); |
| 80 | url!.searchParams.delete("_token"); |
| 81 | globalThis.window?.history?.replaceState(null, "", url!.pathname + url!.search + url!.hash); |
| 82 | applyBearer(fromUrl); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | if (stripCacheBust) { |
| 87 | globalThis.window?.history?.replaceState(null, "", url!.pathname + url!.search + url!.hash); |
| 88 | } |
| 89 | |
| 90 | const stored = readStoredToken(); |
| 91 | if (stored) applyBearer(stored); |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * Persist a token entered manually (the login gate) and reload. The gate |
no test coverage detected