import { useAuth } from "@tailor-platform/app-shell";
import { useOnline } from "@/hooks/use-online";
import { ConnectivityErrorScreen } from "./connectivity-error-screen";
import { Spinner } from "./ui/spinner";
/**
* Pre-auth guard provided to ``.
*
* Decision matrix:
* - auth bootstrap in flight (`!isReady`) -> loading spinner
* - browser offline -> connectivity error
* (without this branch, an offline browser fails the auth bootstrap and
* app-shell reports `isAuthenticated === false`, so we'd otherwise show
* "Sign in required" — misleading, since there's nothing to sign into.)
* - authenticated user not yet present -> "Sign in required"
* - otherwise -> falls through (children render)
*/
export const AuthGuard = () => {
const { isReady, isAuthenticated, login } = useAuth();
const online = useOnline();
if (!isReady) {
return (
Loading…
);
}
// Browser-level offline check. `useOnline` re-renders this component when
// the browser fires `online`/`offline`, so the moment connectivity returns
// we transparently retry the auth flow without a manual refresh.
if (!online) {
return ;
}
if (!isAuthenticated) {
return (
Sign in required
Continue with your Tailor account to access this app.