Site / foldkit-site
Guarding which routes a visitor sees
Route access rules control presentation — redirecting an unauthenticated visitor
to /sign-in instead of flashing an empty screen. Always enforce data
authorization on the server with foldkit-guard and RemoteServer.
Attach access to a node to specify who may see it and its descendants, plus
where anyone else should go:
ts
const Projects = Site.node(pipe(literal('projects'), mapTo(AppRoute.Projects)), AppRoute.Projects)
.access<Me>({ allow: me => me.signedIn, otherwise: toSignIn })
.nodeCall Site.accessOf(site, route, who) and branch with Access.match:
Allowed: Render the route.Pending:whoisOption.none()(still loading); show a loading state instead of flashing sign-in.Denied: Replace the URL withotherwise(requested)in the browser, or return a303redirect on the server. Mounting theotherwisetarget inside a subtree protected by the same rule throws at runtime to prevent redirect loops.