Skip to content

Commit f3d409f

Browse files
authored
Do not use location.reload at login (#1222)
1 parent f94446b commit f3d409f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

admin/authentication-support.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In short, you have to tweak data provider and api documentation parser, like thi
1111

1212
import React from "react";
1313
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";
1515
import parseHydraDocumentation from "@api-platform/api-doc-parser/lib/hydra/parseHydraDocumentation";
1616
import authProvider from "./authProvider";
1717

@@ -26,6 +26,15 @@ const fetchHydra = (url, options = {}) =>
2626
headers: new Headers(fetchHeaders()),
2727
})
2828
: 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+
}
2938
const apiDocumentationParser = (entrypoint) =>
3039
parseHydraDocumentation(
3140
entrypoint,
@@ -42,9 +51,7 @@ const apiDocumentationParser = (entrypoint) =>
4251
return Promise.resolve({
4352
api: result.api,
4453
customRoutes: [
45-
<Route path="/" render={() => {
46-
return localStorage.getItem("token") ? window.location.reload() : <Redirect to="/login" />
47-
}} />
54+
<Route path="/" component={RedirectToLogin} />
4855
],
4956
});
5057
}

0 commit comments

Comments
 (0)