Restore the auth-token dialog when an installed PWA receives a daemon 401 before React mounts. - Latch daemon authentication failures for mount-time recovery. - Clear the latch when the authentication token changes. - Cover cold-start recovery and successful-response behavior with dashboard tests. Files changed: .changeset/fn-8301-pwa-auth-recovery.md | 7 +++ packages/dashboard/app/__tests__/auth.test.ts | 40 ++++++++++++++ packages/dashboard/app/auth.ts | 8 +++ .../hooks/__tests__/useAuthTokenRecovery.test.ts | 61 +++++++++++++++++++++- .../dashboard/app/hooks/useAuthTokenRecovery.ts | 10 ++-- 5 files changed, 121 insertions(+), 5 deletions(-) Fusion-Task-Id: FN-8301 Fusion-Task-Lineage: b35236f4-af3d-4313-8b7d-6cd59a237144 Co-authored-by: Fusion (runfusion.ai) <noreply@runfusion.ai>
33 lines
1017 B
TypeScript
33 lines
1017 B
TypeScript
/*
|
|
FNXC:AuthTokenRecovery 2026-07-14-00:00:
|
|
App-level open state for the auth-token recovery dialog follows the daemon's auth-failure event and its latch. Cold PWA and bare-URL 401s can fire before React mounts this listener, so the mount-time latch read must open recovery for that missed one-shot event.
|
|
*/
|
|
|
|
import { useEffect, useState } from "react";
|
|
import { AUTH_TOKEN_RECOVERY_REQUIRED_EVENT, hasDaemonAuthFailure } from "../auth";
|
|
|
|
export interface UseAuthTokenRecoveryResult {
|
|
open: boolean;
|
|
}
|
|
|
|
export function useAuthTokenRecovery(): UseAuthTokenRecoveryResult {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const handleDaemonAuthFailure = () => {
|
|
setOpen(true);
|
|
};
|
|
|
|
window.addEventListener(AUTH_TOKEN_RECOVERY_REQUIRED_EVENT, handleDaemonAuthFailure);
|
|
if (hasDaemonAuthFailure()) {
|
|
setOpen(true);
|
|
}
|
|
|
|
return () => {
|
|
window.removeEventListener(AUTH_TOKEN_RECOVERY_REQUIRED_EVENT, handleDaemonAuthFailure);
|
|
};
|
|
}, []);
|
|
|
|
return { open };
|
|
}
|