diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index e6e15e867..079d56dcf 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -17,19 +17,19 @@ export const checkLogin = () => ( if (!result.user) { cleanAuthData(localStorage); dispatch(checkLoginSuccess(null)); + client.resetWebsocket(); return; } - // Reset the websocket. - client.resetWebsocket(); - dispatch(checkLoginSuccess(result.user)); pym.sendMessage('coral-auth-changed', JSON.stringify(result.user)); + client.resetWebsocket(); }) .catch(error => { if (error.status && error.status === 401 && localStorage) { // Unauthorized. cleanAuthData(localStorage); + client.resetWebsocket(); } else { console.error(error); } diff --git a/client/coral-framework/reducers/config.js b/client/coral-framework/reducers/config.js index b063f9b97..d1c6e23fe 100644 --- a/client/coral-framework/reducers/config.js +++ b/client/coral-framework/reducers/config.js @@ -3,9 +3,11 @@ import { ENABLE_PLUGINS_DEBUG, DISABLE_PLUGINS_DEBUG, } from '../constants/config'; -import { LOGOUT } from '../constants/auth'; +import { LOGOUT, SET_AUTH_TOKEN } from '../constants/auth'; -const initialState = {}; +const initialState = { + auth_token: null, +}; export default function config(state = initialState, action) { switch (action.type) { @@ -30,6 +32,11 @@ export default function config(state = initialState, action) { ...state, auth_token: null, }; + case SET_AUTH_TOKEN: + return { + ...state, + auth_token: action.token || null, + }; case MERGE_CONFIG: return { ...state, diff --git a/client/coral-framework/services/bootstrap.js b/client/coral-framework/services/bootstrap.js index 9bfec2acd..be0955d8f 100644 --- a/client/coral-framework/services/bootstrap.js +++ b/client/coral-framework/services/bootstrap.js @@ -42,17 +42,13 @@ const getAuthToken = (store, storage) => { let state = store.getState(); if (state.config && state.config.auth_token) { - // if an auth_token exists in config, use it. - return state.config.auth_token; + // If the embed is called with `embed.login(token)`, and the browser is not + // capable of storing the token in localStorage, then we would have + // persisted it to the redux state. + return state.config.auth_token || state.auth.token; } else if (!bowser.safari && !bowser.ios && storage) { // Use local storage auth tokens where there's a stable api. return storage.getItem('token'); - } else if (state.auth && state.auth.token) { - // Use the redux token state if the remaining methods fall out. If the embed - // is called with `embed.login(token)`, and the browser is not capable of - // storing the token in localStorage, then we would have persisted it to the - // redux state. - return state.auth.token; } return null;