<ProtectedRoute> and <GuestRoute>.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Control access to your application pages based on authentication state.
<ProtectedRoute> and <GuestRoute>.
<ProtectedRoute>import { ProtectedRoute } from '@urbackend/react';
import Dashboard from './Dashboard';
export default function ProtectedDashboard() {
return (
<ProtectedRoute
fallback={<div>Loading session...</div>}
onRedirect={() => window.location.href = '/login'}
>
<Dashboard />
</ProtectedRoute>
);
}
<GuestRoute>import { GuestRoute, UrAuth } from '@urbackend/react';
export default function LoginPage() {
return (
<GuestRoute
fallback={<div>Loading...</div>}
onRedirect={() => window.location.href = '/dashboard'}
>
<UrAuth providers={['google', 'github']} />
</GuestRoute>
);
}
| Prop | Type | Required | Description |
|---|---|---|---|
fallback | React.ReactNode | Yes | What to render while the SDK is checking the authentication state (e.g. a spinner). |
onRedirect | () => void | Yes | A callback fired when the user needs to be redirected. You can use your framework’s router (e.g. next/navigation or react-router-dom) inside this callback. |
children | React.ReactNode | Yes | The components to render if the access condition is met. |
Was this page helpful?
