From 4982d8a9adbf9f20fb56547d35cc49de94bbf42b Mon Sep 17 00:00:00 2001 From: Max Eddy Date: Thu, 8 Jun 2017 11:22:07 -0400 Subject: [PATCH] Use REST API result for check login message. --- client/coral-embed/src/index.js | 6 +++--- client/coral-framework/actions/auth.js | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index d90591f2f..c6c29c30e 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -54,9 +54,9 @@ function configurePymParent(pymParent, opts) { pymParent.sendMessage('config', JSON.stringify(config)); } - pymParent.onMessage('checkLogin', function(result) { - if (opts.onAuthChange) { - opts.onAuthChange(JSON.parse(result)); + pymParent.onMessage('coral-check-login', function(result) { + if (opts.onCheckLogin) { + opts.onCheckLogin(JSON.parse(result)); } }); diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index e4871a7e2..13a1bc24e 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -301,10 +301,12 @@ const checkLoginSuccess = (user, isAdmin) => ({ isAdmin }); -export const checkLogin = () => (dispatch, getState) => { +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) { Storage.removeItem('token'); @@ -325,9 +327,6 @@ export const checkLogin = () => (dispatch, getState) => { .catch((error) => { console.error(error); dispatch(checkLoginFailure(`${error.translation_key}`)); - }) - .then(() => { - pym.sendMessage('checkLogin', JSON.stringify(getState().auth)); }); };