Skip to content

Commit f6fbe0e

Browse files
committed
Close to working!
1 parent 9145f7f commit f6fbe0e

File tree

2 files changed

+19
-41
lines changed

2 files changed

+19
-41
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
"version": "1.0.0",
44
"private": true,
55
"dependencies": {
6-
"apollo-boost": "^0.4.7",
7-
"apollo-link-context": "^1.0.19",
86
"firebase": "^7.9.x",
9-
"graphql": "^14.5.8",
107
"prop-types": "^15.7.2",
11-
"ra-data-hasura-graphql": "^0.1.8",
8+
"ra-data-hasura": "0.0.8",
129
"react": "^16.13.1",
1310
"react-admin": "^3.1.2",
1411
"react-admin-firebase": "^3.1.4",

src/App.js

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import React from 'react';
2-
import {Admin, Resource} from 'react-admin';
2+
import {fetchUtils, Admin, Resource} from 'react-admin';
33
import {TodoCreate, TodoEdit, TodoList} from './todos';
44
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';
128
import {FirebaseAuthProvider} from 'react-admin-firebase';
139

1410

@@ -31,56 +27,41 @@ const firebaseOptions = {
3127

3228

3329
// Define Hasura data provider
34-
const hasuraUri = "http://localhost:8081/v1/graphql";
30+
const hasuraUri = "http://localhost:8081";
3531

3632

3733
// Define main App
3834
const App = async () => {
3935
const authProvider = FirebaseAuthProvider(firebaseConfig, firebaseOptions);
4036
//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);
6645
};
46+
const dataProvider = hasuraDataProvider(hasuraUri, httpClient);
47+
6748

6849
return () => (
6950
<Admin
70-
dataProvider={hasuraDataProvider}
51+
dataProvider={dataProvider}
7152
authProvider={authProvider}
7253
// dashboard={Dashboard}
7354
>
7455
<Resource
7556
name="todos"
76-
icon={PostIcon}
57+
//icon={PostIcon}
7758
list={TodoList}
7859
edit={TodoEdit}
7960
create={TodoCreate}
8061
/>
8162
<Resource
8263
name="users"
83-
icon={UserIcon}
64+
//icon={UserIcon}
8465
list={UserList}
8566
show={UserShow}
8667
/>

0 commit comments

Comments
 (0)