Skip to content

Commit

Permalink
handle already logged out case more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
burnettk committed Oct 30, 2023
1 parent 0d1c1bb commit aa642a4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions spiffworkflow-frontend/src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { BACKEND_BASE_URL } from '../config';
// Some explanation:
// https://dev.to/nilanth/how-to-secure-jwt-in-a-single-page-application-cko

const SIGN_IN_PATH = '/';

const getCookie = (key: string) => {
const parsedCookies = cookie.parse(document.cookie);
if (key in parsedCookies) {
Expand Down Expand Up @@ -61,9 +63,16 @@ const getIdToken = () => {

const doLogout = () => {
const idToken = getIdToken();
const redirectUrl = `${window.location.origin}`;
const url = `${BACKEND_BASE_URL}/logout?redirect_url=${redirectUrl}&id_token=${idToken}`;
window.location.href = url;

const frontendBaseUrl = window.location.origin;
let logoutRedirectUrl = `${BACKEND_BASE_URL}/logout?redirect_url=${frontendBaseUrl}&id_token=${idToken}`;

// edge case. if the user is already logged out, just take them somewhere that will force them to sign in.
if (idToken === null) {
logoutRedirectUrl = SIGN_IN_PATH;
}

window.location.href = logoutRedirectUrl;
};

const getAccessToken = () => {
Expand Down

0 comments on commit aa642a4

Please sign in to comment.