From 03c1bcad11b166176cfd318a448e4f329c576ecd Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 15 Jan 2020 04:32:45 -0800 Subject: [PATCH] Log users out if tokens have expired, force FB users to login on startup Summary: Currently there are several issues caused by internal users not being logged in. E.g. the rating button doesn't work, flipper traces can't be uploaded etc. However, the fact that the user is not logged in, is not reflected in the UI if the user has an API key, which is outdated. See also the scuba query in the linked tasks; this happens for quite some users. This diff fixes two things: 1. If auth tokens are invalid, this is properly reflected in the UI 2. If at startup the profile can't be loaded, a popup will be shown to log in. Differential Revision: D19392735 fbshipit-source-id: 2be7c577ead671df16c626c0636e89245cebab14 --- src/chrome/UserAccount.tsx | 19 ++++++++++++++++--- src/dispatcher/user.tsx | 7 +++++-- src/reducers/user.tsx | 3 +++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/chrome/UserAccount.tsx b/src/chrome/UserAccount.tsx index 965c8a3ed..13fda40cc 100644 --- a/src/chrome/UserAccount.tsx +++ b/src/chrome/UserAccount.tsx @@ -7,7 +7,7 @@ * @format */ -import {User} from '../reducers/user'; +import {User, USER_UNAUTHORIZED, USER_NOT_SIGNEDIN} from '../reducers/user'; import {ActiveSheet} from '../reducers/application'; import {styled, FlexRow, Glyph, Text, colors} from 'flipper'; @@ -17,6 +17,8 @@ import {connect} from 'react-redux'; import electron from 'electron'; import {findDOMNode} from 'react-dom'; import React, {PureComponent} from 'react'; +import {getUser} from '../fb-stubs/user'; +import config from '../fb-stubs/config'; const Container = styled(FlexRow)({ alignItems: 'center', @@ -86,6 +88,18 @@ class UserAccount extends PureComponent { }); }; + openLogin = () => this.props.setActiveSheet(ACTIVE_SHEET_SIGN_IN); + + componentDidMount() { + if (config.showLogin) { + getUser().catch(error => { + if (error === USER_UNAUTHORIZED || error === USER_NOT_SIGNEDIN) { + this.openLogin(); + } + }); + } + } + render() { const {user} = this.props; const name = user ? user.name : null; @@ -98,8 +112,7 @@ class UserAccount extends PureComponent { ) : ( - this.props.setActiveSheet(ACTIVE_SHEET_SIGN_IN)}> + { @@ -17,7 +17,10 @@ export default (store: Store, logger: Logger) => { .then(user => { store.dispatch(login(user)); }) - .catch(console.debug); + .catch(e => { + store.dispatch(logout()); + console.error(e); + }); let prevUserName = store.getState().user.name; store.subscribe(() => { diff --git a/src/reducers/user.tsx b/src/reducers/user.tsx index fbbb909f8..5fc49fbbf 100644 --- a/src/reducers/user.tsx +++ b/src/reducers/user.tsx @@ -9,6 +9,9 @@ import {Actions} from './'; +export const USER_UNAUTHORIZED = 'Unauthorized.'; +export const USER_NOT_SIGNEDIN = 'Not signed in.'; + export type User = { name?: string; profile_picture?: {