handle already logged out case more gracefully (#599)
Co-authored-by: burnettk <burnettk@users.noreply.github.com>
This commit is contained in:
parent
11512a888e
commit
9f3fba3000
|
@ -11,6 +11,8 @@ import { BACKEND_BASE_URL } from '../config';
|
||||||
// Some explanation:
|
// Some explanation:
|
||||||
// https://dev.to/nilanth/how-to-secure-jwt-in-a-single-page-application-cko
|
// https://dev.to/nilanth/how-to-secure-jwt-in-a-single-page-application-cko
|
||||||
|
|
||||||
|
const SIGN_IN_PATH = '/';
|
||||||
|
|
||||||
const getCookie = (key: string) => {
|
const getCookie = (key: string) => {
|
||||||
const parsedCookies = cookie.parse(document.cookie);
|
const parsedCookies = cookie.parse(document.cookie);
|
||||||
if (key in parsedCookies) {
|
if (key in parsedCookies) {
|
||||||
|
@ -61,9 +63,16 @@ const getIdToken = () => {
|
||||||
|
|
||||||
const doLogout = () => {
|
const doLogout = () => {
|
||||||
const idToken = getIdToken();
|
const idToken = getIdToken();
|
||||||
const redirectUrl = `${window.location.origin}`;
|
|
||||||
const url = `${BACKEND_BASE_URL}/logout?redirect_url=${redirectUrl}&id_token=${idToken}`;
|
const frontendBaseUrl = window.location.origin;
|
||||||
window.location.href = url;
|
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 = () => {
|
const getAccessToken = () => {
|
||||||
|
|
Loading…
Reference in New Issue