File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { Admin , Resource } from 'react-admin' ;
3
3
import Dashboard from './Dashboard' ;
4
+ import authProvider from './authProvider' ;
4
5
import { PostList , PostEdit , PostCreate } from './posts' ;
5
6
import { UserList } from './users' ;
6
7
import jsonServerProvider from 'ra-data-json-server' ;
@@ -9,7 +10,7 @@ import UserIcon from '@material-ui/icons/Group';
9
10
10
11
const dataProvider = jsonServerProvider ( 'http://jsonplaceholder.typicode.com' ) ;
11
12
const App = ( ) => (
12
- < Admin dashboard = { Dashboard } dataProvider = { dataProvider } >
13
+ < Admin dashboard = { Dashboard } authProvider = { authProvider } dataProvider = { dataProvider } >
13
14
< Resource name = "users" list = { UserList } icon = { UserIcon } />
14
15
< Resource name = "posts" list = { PostList } edit = { PostEdit } create = { PostCreate } icon = { PostIcon } />
15
16
</ Admin >
Original file line number Diff line number Diff line change
1
+ export default {
2
+ // called when the user attempts to log in
3
+ login : ( { username } ) => {
4
+ localStorage . setItem ( 'username' , username ) ;
5
+ // accept all username/password combinations
6
+ return Promise . resolve ( ) ;
7
+ } ,
8
+ // called when the user clicks on the logout button
9
+ logout : ( ) => {
10
+ localStorage . removeItem ( 'username' ) ;
11
+ return Promise . resolve ( ) ;
12
+ } ,
13
+ // called when the API returns an error
14
+ checkError : ( { status } ) => {
15
+ if ( status === 401 || status === 403 ) {
16
+ localStorage . removeItem ( 'username' ) ;
17
+ return Promise . reject ( ) ;
18
+ }
19
+ return Promise . resolve ( ) ;
20
+ } ,
21
+ // called when the user navigates to a new location, to check for authentication
22
+ checkAuth : ( ) => {
23
+ return localStorage . getItem ( 'username' )
24
+ ? Promise . resolve ( )
25
+ : Promise . reject ( ) ;
26
+ } ,
27
+ // called when the user navigates to a new location, to check for permissions / roles
28
+ getPermissions : ( ) => Promise . resolve ( ) ,
29
+ } ;
You can’t perform that action at this time.
0 commit comments