Skip to content
Snippets Groups Projects
Verified Commit 7a2c74b9 authored by Adrian Paschkowski's avatar Adrian Paschkowski :thinking:
Browse files

Fix token expired redirect

parent 8cdd93c5
Branches
No related tags found
No related merge requests found
# Self Service Frontend
- TODO: Automatically log out when token is invalid/expired
import { useNavigate } from "react-router-dom";
import useEvents from "../../data/events/useEvents";
import { EventTypes } from "../../data/events/eventTypes";
import ApiActions from "../../data/ApiActions";
export default function ApiErrorShell() {
const navigate = useNavigate();
......@@ -10,6 +11,7 @@ export default function ApiErrorShell() {
case EventTypes.API_CALL_FAIL:
// If the stored token has expired, the user will have to log in again
if (data.response.status === 401) {
ApiActions.forceLogout();
navigate("/login");
}
break;
......
......@@ -213,6 +213,12 @@ export default class ApiActions {
);
}
public static forceLogout(): void {
this.clearStores();
Events.emit(EventTypes.LOGOUT_SUCCESS);
Events.emit(EventTypes.LOGOUT_COMPLETE);
}
private static invokeApi<T>(
start: () => Promise<ApiResponse<T>>,
success: (data: T) => void,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment