Back to React Admin

Authenticated

docs_headless/src/content/docs/Authenticated.md

5.14.61.6 KB
Original Source

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).

Usage

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

jsx
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>
);

Props

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.