Skip to content

<Authenticated>

The <Authenticated> component calls authProvider.checkAuth() on mount. If the current user is authenticated,<Authenticated> renders its child component. If the user is not authenticated, it redirects to the login page. While the authentication is being checked, <Authenticated> displays a loading component (empty by default).

Use it as an alternative to the useAuthenticated() hook when you can’t use a hook, e.g. inside a <Route element> component:

import { CoreAdmin, CustomRoutes, Authenticated } from 'ra-core';
import { Route } from 'react-router-dom';
const App = () => (
<CoreAdmin authProvider={authProvider}>
<CustomRoutes>
<Route path="/foo" element={<Authenticated><Foo /></Authenticated>} />
<Route path="/anoonymous" element={<Baz />} />
</CustomRoutes>
</CoreAdmin>
);
PropRequiredTypeDefaultDescription
childrenRequiredReactNodeThe component to render if the user is authenticated.
authParamsany{}An object containing the parameters to pass to the authProvider.checkAuth() call.
loadingReactNodenullComponent to display while the authentication is being checked.