diff --git a/app/components/Authenticated.js b/app/components/Authenticated.js index 29e43e574..14f53c3eb 100644 --- a/app/components/Authenticated.js +++ b/app/components/Authenticated.js @@ -34,7 +34,7 @@ const Authenticated = observer(({ auth, children }: Props) => { return children; } - auth.logout(); + auth.logout(true); return null; }); diff --git a/app/scenes/Home.js b/app/scenes/Home.js index 39825cd57..8c218f7fb 100644 --- a/app/scenes/Home.js +++ b/app/scenes/Home.js @@ -10,7 +10,7 @@ type Props = { const Home = observer(({ auth }: Props) => { if (auth.authenticated) return ; - auth.logout(); + auth.logout(true); return null; }); diff --git a/app/stores/AuthStore.js b/app/stores/AuthStore.js index 8deb015b9..89f1476fe 100644 --- a/app/stores/AuthStore.js +++ b/app/stores/AuthStore.js @@ -76,6 +76,13 @@ export default class AuthStore { team: team.name, }; } + + // If we came from a redirect then send the user immediately there + const postLoginRedirectPath = getCookie('postLoginRedirectPath'); + if (postLoginRedirectPath) { + removeCookie('postLoginRedirectPath'); + window.location.href = postLoginRedirectPath; + } }); } catch (err) { if (err.error === 'user_suspended') { @@ -133,9 +140,21 @@ export default class AuthStore { }; @action - logout = async () => { - this.user = null; - this.token = null; + logout = async (savePath: boolean = false) => { + // remove user and team from localStorage + localStorage.setItem( + AUTH_STORE, + JSON.stringify({ + user: null, + team: null, + }) + ); + + // if this logout was forced from an authenticated route then + // save the current path so we can go back there once signed in + if (savePath) { + setCookie('postLoginRedirectPath', window.location.pathname); + } // remove authentication token itself removeCookie('accessToken', { path: '/' });