1
1
import React from 'react' ;
2
- import { Admin , Resource } from 'react-admin' ;
2
+ import { fetchUtils , Admin , Resource } from 'react-admin' ;
3
3
import { TodoCreate , TodoEdit , TodoList } from './todos' ;
4
4
import { UserList , UserShow } from './users' ;
5
- import buildHasuraProvider from 'ra-data-hasura-graphql' ;
6
- import PostIcon from '@material-ui/icons/Book' ;
7
- import UserIcon from '@material-ui/icons/Group' ;
8
- import { ApolloClient } from 'apollo-client' ;
9
- import { createHttpLink } from 'apollo-link-http' ;
10
- import { setContext } from 'apollo-link-context' ;
11
- import { InMemoryCache } from 'apollo-cache-inmemory' ;
5
+ import hasuraDataProvider from 'ra-data-hasura' ;
6
+ //import PostIcon from '@material-ui/icons/Book';
7
+ //import UserIcon from '@material-ui/icons/Group';
12
8
import { FirebaseAuthProvider } from 'react-admin-firebase' ;
13
9
14
10
@@ -31,56 +27,41 @@ const firebaseOptions = {
31
27
32
28
33
29
// Define Hasura data provider
34
- const hasuraUri = "http://localhost:8081/v1/graphql " ;
30
+ const hasuraUri = "http://localhost:8081" ;
35
31
36
32
37
33
// Define main App
38
34
const App = async ( ) => {
39
35
const authProvider = FirebaseAuthProvider ( firebaseConfig , firebaseOptions ) ;
40
36
//let firebaseJWT = await authProvider.getJWTToken();
41
- //console.log(`JWT: ${firebaseJWT}`);
42
- // When we aren't logged in, we want to use the anonymous hasura role. When we are, change the client to include the bearer token.
43
- // Below sets headers to anonymous if JWT is null, otherwise it sets them properly
44
- // var apolloHeaders = (!firebaseJWT) ? {'x-hasura-role': 'anonymous'} : {authorization: `Bearer ${firebaseJWT}`, };
45
- // var usertype = (!firebaseJWT) ? 'null condition' : 'logged in';
46
-
47
- let hasuraDataProvider = authProvider . getJWTToken ( ) . then ( function ( JWT ) {
48
- const httpLink = createHttpLink ( {
49
- uri : hasuraUri ,
50
- } ) ;
51
- const authLink = setContext ( ( _ , { headers } ) => {
52
- console . log ( `Token: ${ JWT } ` ) ;
53
- // return the headers to the context so httpLink can read them
54
- return {
55
- headers : {
56
- ...headers ,
57
- ...( JWT ? { authorization : `Bearer ${ JWT } ` } : { } ) ,
58
- }
59
- }
60
- } ) ;
61
- const apolloClientInstance = new ApolloClient ( {
62
- link : authLink . concat ( httpLink ) ,
63
- cache : new InMemoryCache ( ) ,
64
- } ) ;
65
- return buildHasuraProvider ( { client : apolloClientInstance } )
37
+ const httpClient = ( url , options = { } ) => {
38
+ if ( ! options . headers ) {
39
+ options . headers = new Headers ( { Accept : 'application/json' } ) ;
40
+ }
41
+ // add your own headers here
42
+ authProvider . getJWTToken ( ) . then ( function ( JWT ) {
43
+ options . headers . set ( 'Authorization' , `Bearer ${ JWT } ` ) } ) ;
44
+ return fetchUtils . fetchJson ( url , options ) ;
66
45
} ;
46
+ const dataProvider = hasuraDataProvider ( hasuraUri , httpClient ) ;
47
+
67
48
68
49
return ( ) => (
69
50
< Admin
70
- dataProvider = { hasuraDataProvider }
51
+ dataProvider = { dataProvider }
71
52
authProvider = { authProvider }
72
53
// dashboard={Dashboard}
73
54
>
74
55
< Resource
75
56
name = "todos"
76
- icon = { PostIcon }
57
+ // icon={PostIcon}
77
58
list = { TodoList }
78
59
edit = { TodoEdit }
79
60
create = { TodoCreate }
80
61
/>
81
62
< Resource
82
63
name = "users"
83
- icon = { UserIcon }
64
+ // icon={UserIcon}
84
65
list = { UserList }
85
66
show = { UserShow }
86
67
/>
0 commit comments