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

Reset app auth state if Auth0 session has expired #1398

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
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
Loading