Skip to content

Commit

Permalink
Reset app auth state if Auth0 session has expired (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroerbrian authored Nov 8, 2024
1 parent 6817ee3 commit 9a210ec
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/utils/useAppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useContext,
} from "react";
import auth0, { Auth0Result, WebAuth } from "auth0-js";
import { useHistory } from "react-router-dom";
import * as Sentry from "@sentry/browser";
import * as SessionCacher from "utils/SessionCacher";
import * as AuthService from "utils/AuthService";
Expand Down Expand Up @@ -69,6 +70,7 @@ export const AppProvider = ({
userLocation: GeoCoordinates | null;
setBookmarksMenuOpen: (open: boolean) => void;
}) => {
const history = useHistory();
const authObject = SessionCacher.getAuthObject();
const [authState, setAuthState] = useState<AuthState>(authObject);

Expand Down Expand Up @@ -133,6 +135,11 @@ export const AppProvider = ({
})
.catch((err) => {
Sentry.captureException(err);
if (typeof err === "object" && err.code === "login_required") {
setAuthState(null);
// Redirect user to log-in page now that their auth state has been reset
history.push("/log-in");
}
});
}

Expand Down

0 comments on commit 9a210ec

Please sign in to comment.