React Router
Route guards and revalidation for React Router.
import { … } from "@monarcode/session-kit/react-router";Guide: React Router.
Functions
redirectIfSignedIn
Sends a signed-in user from your sign-in page straight to redirectTo, made safe with safeReturnTo, inside a loader of your own. When the loader does nothing else, use redirectIfSignedInLoader instead.
redirectIfSignedInLoader
Makes the loader for your sign-in page, for loader or clientLoader. It reads ?redirectTo= from the URL and works as redirectIfSignedIn does. A loginPath that doesn't start with / throws INVALID_OPTIONS when the loader is made.
requireSession
Checks for a signed-in user inside a loader of your own, in data or framework mode, and resolves { session }, which holds no tokens. When the loader does nothing else, use requireSessionLoader as the loader instead.
requireSessionLoader
Makes the loader that guards a route, for loader or clientLoader, so only signed-in users get through. It resolves { session }, typed with the client's user, and works as requireSession does.
useAuthRevalidation
Runs your loaders again when the session changes, so guards such as requireSession check it again. That's on sign-in, sign-out, a switch of account, a profile update, a lock, or a refresh that fails once the access token has expired. A token refresh alone doesn't, nor does a failed refresh while the token is still valid.
Components
SessionOutlet
Renders child routes only while someone is signed in, in any mode. It needs an AuthProvider above it, or a client.
Types
RedirectIfSignedInLoader
The loader that redirectIfSignedInLoader makes. It reads redirectTo from the request's URL, and resolves null for a signed-out user.
RedirectIfSignedInLoaderOptions
Options for redirectIfSignedInLoader.
Prop
Type
RedirectIfSignedInOptions
Options for redirectIfSignedIn.
Prop
Type
RequireSessionLoader
The loader that requireSessionLoader makes. It resolves { session }, typed with the client's user.
RequireSessionLoaderOptions
Options for requireSessionLoader.
Prop
Type
RequireSessionOptions
Options for requireSession.
Prop
Type
SessionOutletProps
Props for SessionOutlet.
Prop
Type
UnavailableProps
What the unavailable render prop of an adapter component, such as React Router's SessionOutlet or Expo's SessionGate, receives.