API reference
The public surface of
@thunderid/tanstack-router, as documented in its reference pages.<CallbackRoute />The `CallbackRoute` component handles the OAuth 2.0 authorization code callback. Mount it at your application's redirect URI path. It processes the authorization code, validates the CSRF state parameter, exchanges the code for tokens, and navigates the user back to their original destination. :::note `CallbackRoute` must be rendered inside a `ThunderIDProvider` and a TanStack Router context. :::
onErroroptional(error: Error) => voidCalled when callback processing fails (e.g., invalid state, token exchange error)
onNavigateoptional(path: string) => voidOverride the default post-callback navigation. Receives the resolved destination path. Defaults to TanStack Router's `router.navigate()`
import { createRoute } from '@tanstack/react-router'
import { CallbackRoute } from '@thunderid/tanstack-router'
const callbackRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/callback',
component: CallbackRoute,
})<ProtectedRoute />The `ProtectedRoute` component wraps a route component and enforces authentication. When the user is not signed in it either redirects to a specified URL or renders a fallback element. While authentication state is being resolved it shows a loading state. :::note `ProtectedRoute` must be rendered inside a `ThunderIDProvider`. It also requires TanStack Router's router context: wrap your application with `RouterProvider`. :::
childrenrequiredReactElementThe element to render when the user is authenticated
redirectTooptionalstringPath to redirect unauthenticated users to. Either `redirectTo` or `fallback` must be provided
fallbackoptionalReactElementElement to render when the user is not authenticated. Either `redirectTo` or `fallback` must be provided
loaderoptionalReactNodeElement to render while authentication state is being resolved. Defaults to `null`
import { createRoute } from '@tanstack/react-router'
import { ProtectedRoute } from '@thunderid/tanstack-router'
import Dashboard from './pages/Dashboard'
export const dashboardRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/dashboard',
component: () => (
<ProtectedRoute redirectTo="/signin">
<Dashboard />
</ProtectedRoute>
),
})