@@ -62,38 +62,38 @@ import React from 'react';
62
62
import parseHydraDocumentation from ' @api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation' ;
63
63
import { HydraAdmin , hydraClient , fetchHydra as baseFetchHydra } from ' @api-platform/admin' ;
64
64
import authProvider from ' ./authProvider' ;
65
- import { Redirect } from ' react-router-dom' ;
65
+ import { Route , Redirect } from ' react-router-dom' ;
66
66
67
67
const entrypoint = ' https://demo.api-platform.com' ; // Change this by your own entrypoint
68
- const fetchHeaders = {' Authorization' : ` Bearer ${ window . localStorage .getItem (' token' )} ` };
68
+ const fetchHeaders = {' Authorization' : ` Bearer ${ localStorage .getItem (' token' )} ` };
69
69
const fetchHydra = (url , options = {}) => baseFetchHydra (url, {
70
70
... options,
71
71
headers: new Headers (fetchHeaders),
72
72
});
73
73
const dataProvider = api => hydraClient (api, fetchHydra);
74
- const apiDocumentationParser = entrypoint => parseHydraDocumentation (entrypoint, { headers : new Headers (fetchHeaders) })
75
- . then (
76
- ({ api }) => ({ api } ),
77
- ( result ) => {
78
- switch ( result . status ) {
79
- case 401 :
80
- return Promise . resolve ({
81
- api : result . api ,
82
- customRoutes : [ {
83
- props : {
84
- path : ' / ' ,
85
- render : () => < Redirect to = { ` /login ` } / > ,
86
- },
87
- }] ,
88
- });
89
-
90
- default :
91
- return Promise . reject (result);
92
- }
93
- },
94
- );
95
-
96
- export default props => (
74
+ const apiDocumentationParser = entrypoint =>
75
+ parseHydraDocumentation (entrypoint, {
76
+ headers : new Headers (fetchHeaders ),
77
+ }). then (
78
+ ({ api }) => ({ api }),
79
+ result => {
80
+ const { api , status } = result;
81
+
82
+ if (status === 401 ) {
83
+ return Promise . resolve ( {
84
+ api ,
85
+ status ,
86
+ customRoutes : [
87
+ < Route path = " / " render = {() => < Redirect to = " /login " / > } / > ,
88
+ ],
89
+ });
90
+ }
91
+
92
+ return Promise . reject (result);
93
+ }
94
+ );
95
+
96
+ export default () => (
97
97
< HydraAdmin
98
98
apiDocumentationParser= {apiDocumentationParser}
99
99
authProvider= {authProvider}
0 commit comments