Skip to content

Commit

Permalink
Merge pull request #16 from bento-platform/fix/use-callback-sign-out-…
Browse files Browse the repository at this point in the history
…hook

fix(performSignOut): useCallback for returned function
  • Loading branch information
davidlougheed authored Feb 6, 2024
2 parents bc3e57d + 4dbb547 commit 457abec
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/performSignOut.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";

import { useBentoAuthContext } from "./contexts";
Expand All @@ -12,14 +13,14 @@ export const usePerformSignOut = () => {
const { clientId, postSignOutUrl } = useBentoAuthContext();
const { idToken } = useSelector((state: RootState) => state.auth);
const openIdConfig = useOpenIdConfig();
const endSessionEndpoint = openIdConfig?.end_session_endpoint;

return () => {
return useCallback(() => {
if (!clientId || !postSignOutUrl) {
logMissingAuthContext("clientId", "postSignOutUrl");
return;
}

const endSessionEndpoint: string | undefined = openIdConfig?.end_session_endpoint;
if (!endSessionEndpoint) {
dispatch(signOut());
return;
Expand All @@ -34,5 +35,5 @@ export const usePerformSignOut = () => {
endSessionUrl.searchParams.append("post_logout_redirect_uri", postSignOutUrl);
setLSNotSignedIn(); // Make sure we don't immediately try to sign in again
window.location.href = endSessionUrl.toString();
};
}, [dispatch, clientId, postSignOutUrl, idToken, openIdConfig, endSessionEndpoint]);
};

0 comments on commit 457abec

Please sign in to comment.