diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index c6c29c30e..0a901c341 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,11 +54,15 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } - pymParent.onMessage('coral-check-login', function(result) { - if (opts.onCheckLogin) { - opts.onCheckLogin(JSON.parse(result)); + function onAuthChanged(message) { + if (opts.onAuthChanged) { + opts.onAuthChanged(message ? JSON.parse(message) : null); } - }); + } + + pymParent.onMessage('coral-login', onAuthChanged); + + pymParent.onMessage('coral-logout', onAuthChanged); // Sends config to the child pymParent.onMessage('getConfig', function() { diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 13a1bc24e..b7ec4ee4c 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -285,6 +285,7 @@ export const logout = () => (dispatch) => { resetWebsocket(); dispatch({type: actions.LOGOUT}); + pym.sendMessage('coral-logout'); }); }; @@ -305,7 +306,6 @@ export const checkLogin = () => (dispatch) => { dispatch(checkLoginRequest()); coralApi('/auth') .then((result) => { - pym.sendMessage('coral-check-login', JSON.stringify(result)); if (!result.user) { if (!bowser.safari && !bowser.ios) { @@ -318,6 +318,7 @@ export const checkLogin = () => (dispatch) => { resetWebsocket(); dispatch(checkLoginSuccess(result.user)); + pym.sendMessage('coral-login', JSON.stringify(result.user)); // Display create username dialog if necessary. if (result.user.canEditName && result.user.status !== 'BANNED') {