āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/clerk/clerk-docs/reference/remix/root-auth-loader ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
rootAuthLoader()'
description: The rootAuthLoader function is a helper function that provides the authentication state to your Remix application.
sdk: remixThe rootAuthLoader() function is a helper function that provides the authentication state to your Remix application.
You can use the rootAuthLoader() in two different ways:
You can also pass configuration options to rootAuthLoader() no matter which method you use.
To configure Clerk in your Remix app, you must export the rootAuthLoader() function as the root loader() function.
// Your other imports
// Import `rootAuthLoader`
import { rootAuthLoader } from '@clerk/remix/ssr.server'
// Export `rootAuthLoader()` as the root route `loader`
export const loader: LoaderFunction = (args) => rootAuthLoader(args)
// The rest of your code
If you need to load in additional data, you can pass a callback to rootAuthLoader() that handles the route data loading with auth state.
// Your imports
export const loader: LoaderFunction = (args) => {
return rootAuthLoader(args, ({ req }) => {
const { sessionId, userId, getToken } = req.auth
// Add logic to fetch data
return { yourData: 'here' }
})
}
// The rest of your code
To pass configuration options to rootAuthLoader(), you can pass an optional argument to the rootAuthLoader() function.
// Your imports
export const loader: LoaderFunction = (args) => {
return rootAuthLoader(
args,
({ req }) => {
const { sessionId, userId, getToken } = req.auth
// Add logic to fetch data
return { yourData: 'here' }
},
{
signInForceRedirectUrl: '/dashboard',
},
)
}
// The rest of your code
rootAuthLoader() optionsā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā