From b5383a312e9ce35a25bc31113279fa85760ff699 Mon Sep 17 00:00:00 2001 From: zeppi Date: Tue, 21 Sep 2021 15:12:52 -0400 Subject: [PATCH] better user errors --- ui/redux/actions/app.js | 5 +---- ui/redux/actions/user.js | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index d2229e82a..8a4a15446 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -359,10 +359,7 @@ export function doLbryReady() { // TODO: call doFetchDaemonSettings, then get usage data, and call doAuthenticate once they are loaded into the store const shareUsageData = IS_WEB || window.localStorage.getItem(SHARE_INTERNAL) === 'true'; - /** - * doAuthenticate -> Lbryio.authenticate, then update redux with auth token. - * authenticate: Use auth token to get or create user.getCurrentUser. return user - */ + dispatch( doAuthenticate( appVersion, diff --git a/ui/redux/actions/user.js b/ui/redux/actions/user.js index 9bb284e17..0b32ee28c 100644 --- a/ui/redux/actions/user.js +++ b/ui/redux/actions/user.js @@ -131,20 +131,24 @@ export function doAuthenticate( const user = await Lbryio.fetchUser(DOMAIN, getDefaultLanguage()); console.log('USER', user); if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS); - // put this back , accessToken: tokens.access_token - Lbryio.getTokens().then((tokens) => { - dispatch({ - type: ACTIONS.AUTHENTICATION_SUCCESS, - data: { user, accessToken: tokens.auth_token }, // rename 'accessToken' = auth_token - }); - if (shareUsageData) { - dispatch(doRewardList()); - dispatch(doFetchInviteStatus(false)); - if (callInstall) { - doInstallNew(appVersion, callbackForUsersWhoAreSharingData, DOMAIN); + // put this back: accessToken: tokens.access_token + if (user.error) { + throw new Error(user.error.message); + } else { + Lbryio.getTokens().then((tokens) => { + dispatch({ + type: ACTIONS.AUTHENTICATION_SUCCESS, + data: { user, accessToken: tokens.auth_token }, // rename 'accessToken' = authToken + }); + if (shareUsageData) { + dispatch(doRewardList()); + dispatch(doFetchInviteStatus(false)); + if (callInstall) { + doInstallNew(appVersion, callbackForUsersWhoAreSharingData, DOMAIN); + } } - } - }); + }); + } } catch (error) { if (sessionStorageAvailable) window.sessionStorage.removeItem(AUTH_IN_PROGRESS);