@@ -11,7 +11,7 @@ In short, you have to tweak data provider and api documentation parser, like thi
11
11
12
12
import React from " react" ;
13
13
import { Redirect , Route } from " react-router-dom" ;
14
- import { HydraAdmin , hydraDataProvider as baseHydraDataProvider , fetchHydra as baseFetchHydra } from " @api-platform/admin" ;
14
+ import { HydraAdmin , hydraDataProvider as baseHydraDataProvider , fetchHydra as baseFetchHydra , useIntrospection } from " @api-platform/admin" ;
15
15
import parseHydraDocumentation from " @api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation" ;
16
16
import authProvider from " ./authProvider" ;
17
17
@@ -26,6 +26,15 @@ const fetchHydra = (url, options = {}) =>
26
26
headers: new Headers (fetchHeaders ()),
27
27
})
28
28
: baseFetchHydra (url, options);
29
+ const RedirectToLogin = () => {
30
+ const introspect = useIntrospection ();
31
+
32
+ if (localStorage .getItem (' token' )) {
33
+ introspect ();
34
+ return <>< / > ;
35
+ }
36
+ return < Redirect to= ' /login' / > ;
37
+ }
29
38
const apiDocumentationParser = (entrypoint ) =>
30
39
parseHydraDocumentation (
31
40
entrypoint,
@@ -42,9 +51,7 @@ const apiDocumentationParser = (entrypoint) =>
42
51
return Promise .resolve ({
43
52
api: result .api ,
44
53
customRoutes: [
45
- < Route path= " /" render= {() => {
46
- return localStorage .getItem (" token" ) ? window .location .reload () : < Redirect to= " /login" / >
47
- }} / >
54
+ < Route path= " /" component= {RedirectToLogin} / >
48
55
],
49
56
});
50
57
}
0 commit comments