Skip to content

Commit bfcdcd7

Browse files
committed
update security (wip)
1 parent e11024e commit bfcdcd7

File tree

8 files changed

+205
-280
lines changed

8 files changed

+205
-280
lines changed

docs_headless/src/content/docs/security/AuthProviderList.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ layout: default
33
title: "Supported Auth Provider Backends"
44
---
55

6-
# Supported Auth Provider Backends
7-
86
It's very common that your auth logic is so specific that you'll need to write your own `authProvider`. However, the community has built a few open-source Auth Providers that may fit your need:
97

108
<div class="providers-list" markdown="1">

docs_headless/src/content/docs/security/AuthProviderWriting.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
2-
layout: default
32
title: "Writing An Auth Provider"
43
---
54

6-
# Writing An Auth Provider
7-
85
React-admin can use any authentication backend, but you have to write an adapter for it. This adapter is called an `authProvider`. The `authProvider` is a simple object with methods that react-admin calls to handle authentication and authorization.
96

107
## AuthProvider Interface Overview
@@ -29,7 +26,7 @@ const authProvider = {
2926
**Tip**: If you're a TypeScript user, you can check that your `authProvider` is correct at compile-time using the `AuthProvider` type.
3027

3128
```tsx
32-
import type { AuthProvider } from 'react-admin';
29+
import type { AuthProvider } from 'ra-core';
3330

3431
const authProvider: AuthProvider = {
3532
// ...
@@ -271,7 +268,7 @@ const authProvider = {
271268

272269
### `logout`
273270

274-
If you enable authentication, react-admin adds a logout button in the user menu in the top bar (or in the sliding menu on mobile). When the user clicks on the logout button, this calls the `authProvider.logout()` method, and removes potentially sensitive data stored in [the react-admin Store](./Store.md). Then the user gets redirected to the login page. The two previous sections also illustrated that react-admin can call `authProvider.logout()` itself, when the API returns a 403 error or when the local credentials expire.
271+
If you enable authentication, react-admin adds a logout button in the user menu in the top bar (or in the sliding menu on mobile). When the user clicks on the logout button, this calls the `authProvider.logout()` method, and removes potentially sensitive data stored in [the react-admin Store](../guides/Store.md). Then the user gets redirected to the login page. The two previous sections also illustrated that react-admin can call `authProvider.logout()` itself, when the API returns a 403 error or when the local credentials expire.
275272

276273
<video controls autoplay playsinline muted loop>
277274
<source src="../img/logout.mp4" type="video/mp4"/>
@@ -329,7 +326,7 @@ React-admin uses the `fullName` and the `avatar` (an image source, or a data-uri
329326
**Tip**: You can use the `id` field to identify the current user in your code, by calling the `useGetIdentity` hook:
330327

331328
```jsx
332-
import { useGetIdentity, useGetOne } from 'react-admin';
329+
import { useGetIdentity, useGetOne } from 'ra-core';
333330

334331
const PostDetail = ({ id }) => {
335332
const { data: post, isPending: postLoading } = useGetOne('posts', { id });
@@ -354,7 +351,7 @@ So `handleCallback` lets you process query parameters passed by the third-party
354351
Here's an example using Auth0:
355352

356353
```tsx
357-
import { PreviousLocationStorageKey } from 'react-admin';
354+
import { PreviousLocationStorageKey } from 'ra-core';
358355
import { Auth0Client } from './Auth0Client';
359356

360357
const authProvider = {

docs_headless/src/content/docs/security/Authenticated.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
---
2-
layout: default
3-
title: "The Authenticated Component"
2+
title: "<Authenticated>"
43
---
54

6-
# `<Authenticated>`
7-
85
The `<Authenticated>` component calls [`authProvider.checkAuth()`](./AuthProviderWriting.md#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).
96

107
## Usage
118

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

1411
```jsx
15-
import { Admin, CustomRoutes, Authenticated } from 'react-admin';
12+
import { CoreAdmin, CustomRoutes, Authenticated } from 'ra-core';
1613
import { Route } from 'react-router-dom';
1714

1815
const App = () => (
19-
<Admin authProvider={authProvider}>
16+
<CoreAdmin authProvider={authProvider}>
2017
<CustomRoutes>
2118
<Route path="/foo" element={<Authenticated><Foo /></Authenticated>} />
2219
<Route path="/anoonymous" element={<Baz />} />
2320
</CustomRoutes>
24-
</Admin>
21+
</CoreAdmin>
2522
);
2623
```
2724

0 commit comments

Comments
 (0)