Files
flipper/src/dispatcher/user.tsx
Michel Weststrate 03c1bcad11 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
2020-01-15 04:34:35 -08:00

33 lines
816 B
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger';
import {login, logout} from '../reducers/user';
import {getUser, logoutUser} from '../fb-stubs/user';
export default (store: Store, logger: Logger) => {
getUser()
.then(user => {
store.dispatch(login(user));
})
.catch(e => {
store.dispatch(logout());
console.error(e);
});
let prevUserName = store.getState().user.name;
store.subscribe(() => {
if (prevUserName && !store.getState().user.name) {
logoutUser();
}
prevUserName = store.getState().user.name;
});
};