This commit is contained in:
37
web/src/components/BetaGate.tsx
Normal file
37
web/src/components/BetaGate.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { type ReactNode, useEffect, useState } from "react";
|
||||
import { Navigate, useLocation } from "react-router-dom";
|
||||
|
||||
const STORAGE_KEY = "skymoney_beta_access";
|
||||
|
||||
type Props = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export function BetaGate({ children }: Props) {
|
||||
const location = useLocation();
|
||||
const [hasAccess, setHasAccess] = useState<boolean | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setHasAccess(localStorage.getItem(STORAGE_KEY) === "true");
|
||||
}, []);
|
||||
|
||||
if (location.pathname === "/beta") {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (hasAccess === null) {
|
||||
return (
|
||||
<div className="flex min-h-[40vh] items-center justify-center text-sm muted">
|
||||
Checking access…
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!hasAccess) {
|
||||
return <Navigate to="/beta" replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export const betaAccessStorageKey = STORAGE_KEY;
|
||||
Reference in New Issue
Block a user