diff --git a/client/coral-admin/src/actions/auth.js b/client/coral-admin/src/actions/auth.js index 3304da85f..3209a1aaf 100644 --- a/client/coral-admin/src/actions/auth.js +++ b/client/coral-admin/src/actions/auth.js @@ -33,6 +33,7 @@ export const handleLogin = (email, password, recaptchaResponse) => ( if (!user) { if (!bowser.safari && !bowser.ios && localStorage) { localStorage.removeItem('token'); + localStorage.removeItem('exp'); } return dispatch(checkLoginFailure('not logged in')); } @@ -132,6 +133,7 @@ export const checkLogin = () => ( if (!user) { if (!bowser.safari && !bowser.ios && localStorage) { localStorage.removeItem('token'); + localStorage.removeItem('exp'); } return dispatch(checkLoginFailure('not logged in')); } @@ -154,8 +156,10 @@ export const checkLogin = () => ( export const logout = () => (dispatch, _, { rest, client, localStorage }) => { return rest('/auth', { method: 'DELETE' }).then(() => { + if (localStorage) { localStorage.removeItem('token'); + localStorage.removeItem('exp'); } // Reset the websocket. diff --git a/client/coral-embed-stream/src/actions/auth.js b/client/coral-embed-stream/src/actions/auth.js index ac4b96c2c..d7e2b7826 100644 --- a/client/coral-embed-stream/src/actions/auth.js +++ b/client/coral-embed-stream/src/actions/auth.js @@ -266,6 +266,7 @@ export const logout = () => async ( if (localStorage) { localStorage.removeItem('token'); + localStorage.removeItem('exp'); } // Reset the websocket. @@ -304,6 +305,7 @@ export const checkLogin = () => ( if (!result.user) { if (localStorage) { localStorage.removeItem('token'); + localStorage.removeItem('exp'); } throw ErrNotLoggedIn; } @@ -329,6 +331,7 @@ export const checkLogin = () => ( if (error.status && error.status === 401 && localStorage) { // Unauthorized. localStorage.removeItem('token'); + localStorage.removeItem('exp'); } const errorMessage = error.translation_key ? t(`error.${error.translation_key}`) diff --git a/plugins/talk-plugin-auth/client/components/SignInContainer.js b/plugins/talk-plugin-auth/client/components/SignInContainer.js index a4dec87e5..6f99f9ce6 100644 --- a/plugins/talk-plugin-auth/client/components/SignInContainer.js +++ b/plugins/talk-plugin-auth/client/components/SignInContainer.js @@ -38,8 +38,7 @@ class SignInContainer extends React.Component { } componentDidMount() { - window.addEventListener('storage', this.handleAuth); - + this.listenToStorageChanges(); const { formData } = this.state; const errors = Object.keys(formData).reduce((map, prop) => { map[prop] = t('sign_in.required_field'); @@ -49,6 +48,14 @@ class SignInContainer extends React.Component { } componentWillUnmount() { + this.unlisten(); + } + + listenToStorageChanges() { + window.addEventListener('storage', this.handleAuth); + } + + unlisten() { window.removeEventListener('storage', this.handleAuth); } @@ -60,6 +67,8 @@ class SignInContainer extends React.Component { if (e.key === 'auth') { const { err, data } = JSON.parse(e.newValue); authCallback(err, data); + this.unlisten(); + localStorage.removeItem('auth'); } };