| 41 | ); |
| 42 | |
| 43 | function AuthGate({ children }: { children: ReactNode }) { |
| 44 | const auth = useAuth(); |
| 45 | |
| 46 | // Access already authenticated the user at the edge; an unauthenticated state |
| 47 | // means there's no live Access session (gate not configured, or expired) — |
| 48 | // send them through the Access login, which returns to the app with a JWT. |
| 49 | useEffect(() => { |
| 50 | if (auth.status === "unauthenticated") { |
| 51 | window.location.href = "/cdn-cgi/access/login"; |
| 52 | } |
| 53 | }, [auth.status]); |
| 54 | |
| 55 | if (auth.status === "authenticated") return <>{children}</>; |
| 56 | return ( |
| 57 | <Loading label={auth.status === "unauthenticated" ? "Redirecting to sign in…" : "Loading…"} /> |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | function AuthenticatedApp() { |
| 62 | const auth = useAuth(); |