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