Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StrictMode issue #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
"lodash": "~4.17.5",
"prop-types": "^15.7.2",
"proxy-polyfill": "^0.3.0",
"ra-data-fakerest": "^4.4.0",
"ra-i18n-polyglot": "^4.4.0",
"ra-input-rich-text": "^4.4.0",
"ra-language-english": "^4.4.0",
"ra-language-french": "^4.4.0",
"ra-data-fakerest": "^4.14.0",
"ra-i18n-polyglot": "^4.14.0",
"ra-input-rich-text": "^4.14.0",
"ra-language-english": "^4.14.0",
"ra-language-french": "^4.14.0",
"react": "^18.0.0",
"react-admin": "^4.4.0",
"react-admin": "^4.14.0",
"react-dom": "^18.0.0",
"react-hook-form": "^7.34.2",
"react-query": "^3.32.1",
Expand Down
12 changes: 9 additions & 3 deletions packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const getPermissions = (decoded: KeycloakTokenParsed) => {

const App = () => {
const [keycloak, setKeycloak] = useState<Keycloak>(undefined);
const initializingPromise = useRef<Promise<Keycloak>>(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const authProvider = useRef<AuthProvider>(undefined);
const dataProvider = useRef<DataProvider>(undefined);

Expand All @@ -61,11 +62,16 @@ const App = () => {
myDataProvider,
keycloakClient
);
setKeycloak(keycloakClient);

return keycloakClient;
};
if (!keycloak) {
initKeyCloakClient();
if (!initializingPromise.current) {
initializingPromise.current = initKeyCloakClient();
}

initializingPromise.current.then(keycloakClient => {
setKeycloak(keycloakClient);
});
}, [keycloak]);

// hide the admin until the dataProvider and authProvider are ready
Expand Down
6 changes: 5 additions & 1 deletion packages/demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ import App from './App';
const container = document.getElementById('root');
const root = ReactDOM.createRoot(container);

root.render(<App />);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// can't activate strict mode due to this weird issue https://github.com/react-keycloak/react-keycloak/issues/182
12 changes: 9 additions & 3 deletions packages/ra-keycloak/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const raKeycloakOptions = {

const App = () => {
const [keycloak, setKeycloak] = useState<Keycloak>(undefined);
const initializingPromise = useRef<Promise<Keycloak>>(undefined);
const authProvider = useRef<AuthProvider>(undefined);
const dataProvider = useRef<DataProvider>(undefined);

Expand All @@ -82,11 +83,16 @@ const App = () => {
'$API_URL',
httpClient(keycloakClient)
);
setKeycloak(keycloakClient);
return keycloakClient;
};
if (!keycloak) {
initKeyCloakClient();

if (!initializingPromise.current) {
initializingPromise.current = initKeyCloakClient();
}

initializingPromise.current.then(keycloakClient => {
setKeycloak(keycloakClient);
});
}, [keycloak]);

// hide the admin until the keycloak client is ready
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-keycloak/src/authProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const keycloakAuthProvider = (
return Promise.resolve();
},
async checkAuth() {
return client.authenticated && client.token
return client.authenticated && !!client.token
? Promise.resolve()
: Promise.reject('Failed to obtain access token.');
},
Expand Down
Loading