From 0ad4adcecae5470aa99bb8f892ba35f22249c763 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 1 Nov 2019 12:19:28 -0400 Subject: [PATCH] only sign user out during sign in flow on the password prompt --- src/ui/component/header/index.js | 3 ++- src/ui/component/header/view.jsx | 6 +++++- src/ui/redux/actions/app.js | 4 ++-- src/ui/util/saved-passwords.js | 12 +++++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/ui/component/header/index.js b/src/ui/component/header/index.js index 7324ce971..e4e141955 100644 --- a/src/ui/component/header/index.js +++ b/src/ui/component/header/index.js @@ -1,7 +1,7 @@ import * as SETTINGS from 'constants/settings'; import { connect } from 'react-redux'; import { selectBalance, formatCredits } from 'lbry-redux'; -import { selectUserVerifiedEmail } from 'lbryinc'; +import { selectUserVerifiedEmail, selectGetSyncErrorMessage } from 'lbryinc'; import { doSetClientSetting } from 'redux/actions/settings'; import { doSignOut } from 'redux/actions/app'; import { makeSelectClientSetting } from 'redux/selectors/settings'; @@ -15,6 +15,7 @@ const select = state => ({ automaticDarkModeEnabled: makeSelectClientSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED)(state), hideBalance: makeSelectClientSetting(SETTINGS.HIDE_BALANCE)(state), email: selectUserVerifiedEmail(state), + syncError: selectGetSyncErrorMessage(state), }); const perform = dispatch => ({ diff --git a/src/ui/component/header/view.jsx b/src/ui/component/header/view.jsx index ec4a9ccf8..115e9676e 100644 --- a/src/ui/component/header/view.jsx +++ b/src/ui/component/header/view.jsx @@ -25,6 +25,7 @@ type Props = { hideBalance: boolean, email: ?string, authHeader: boolean, + syncError: ?string, signOut: () => void, }; @@ -39,9 +40,12 @@ const Header = (props: Props) => { email, authHeader, signOut, + syncError, } = props; const authenticated = Boolean(email); - const authHeaderAction = authenticated ? { onClick: signOut } : { navigate: '/' }; + + // Sign out if they click the "x" when they are on the password prompt + const authHeaderAction = syncError ? { onClick: signOut } : { navigate: '/' }; const homeButtonNavigationProps = authHeader ? authHeaderAction : { navigate: '/' }; const closeButtonNavigationProps = authHeader ? authHeaderAction : { onClick: () => history.goBack() }; diff --git a/src/ui/redux/actions/app.js b/src/ui/redux/actions/app.js index 1653bede6..022cce473 100644 --- a/src/ui/redux/actions/app.js +++ b/src/ui/redux/actions/app.js @@ -38,7 +38,7 @@ import { doAuthenticate, doGetSync } from 'lbryinc'; import { lbrySettings as config, version as appVersion } from 'package.json'; import { push } from 'connected-react-router'; import analytics from 'analytics'; -import { deleteCookies, deleteSavedPassword, getSavedPassword } from 'util/saved-passwords'; +import { doSignOutCleanup, deleteSavedPassword, getSavedPassword } from 'util/saved-passwords'; // @if TARGET='app' const { autoUpdater } = remote.require('electron-updater'); @@ -446,7 +446,7 @@ export function doSignIn() { export function doSignOut() { return dispatch => { - deleteCookies() + doSignOutCleanup() .then(() => { // @if TARGET='web' window.persistor.purge(); diff --git a/src/ui/util/saved-passwords.js b/src/ui/util/saved-passwords.js index 2f1f92cd0..f326f947f 100644 --- a/src/ui/util/saved-passwords.js +++ b/src/ui/util/saved-passwords.js @@ -121,11 +121,21 @@ export const deleteAuthToken = () => { }); }; -export const deleteCookies = () => { +export const doSignOutCleanup = () => { return new Promise<*>(resolve => { deleteCookie('auth_token'); deleteCookie('saved-password'); + + // @if TARGET='app' + ipcRenderer.once('delete-auth-token-response', (event, success) => { + resolve(); + }); + ipcRenderer.send('delete-auth-token'); + // @endif; + + // @if TARGET='web' resolve(); + // @endif }); };