# Router Guards (CRITICAL) ## beforeLoad Auth Guard `beforeLoad` runs before the route renders. Throw a redirect to block unauthenticated access: ```typescript import { createFileRoute, redirect } from '@tanstack/react-router' import { createServerFn } from '@tanstack/react-start' import { auth } from '@clerk/tanstack-react-start/server' const checkAuth = createServerFn().handler(async () => { const { isAuthenticated, userId } = await auth() if (!isAuthenticated) { throw redirect({ to: '/sign-in' }) } return { userId } }) export const Route = createFileRoute('/dashboard')({ beforeLoad: async () => await checkAuth(), }) ``` ## Passing Auth to Loader ```typescript export const Route = createFileRoute('/dashboard')({ beforeLoad: async () => { const { userId } = await checkAuth() return { userId } }, loader: async ({ context }) => { const { userId } = context const data = await fetchUserData(userId) return { data } }, component: Dashboard, }) function Dashboard() { const { data } = Route.useLoaderData() return