Convert user dispatcher to TS
Summary: Convert file to TS Reviewed By: passy Differential Revision: D16687861 fbshipit-source-id: 5aa88b169b915bc1abd71d312f510073ea78b0c7
This commit is contained in:
committed by
Facebook Github Bot
parent
7a594cf456
commit
cff023150e
27
src/dispatcher/user.tsx
Normal file
27
src/dispatcher/user.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* 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.js';
|
||||
import {login} from '../reducers/user';
|
||||
import {getUser, logoutUser} from '../fb-stubs/user';
|
||||
|
||||
export default (store: Store, logger: Logger) => {
|
||||
getUser()
|
||||
.then(user => {
|
||||
store.dispatch(login(user));
|
||||
})
|
||||
.catch(console.debug);
|
||||
|
||||
let prevUserName = store.getState().user.name;
|
||||
store.subscribe(() => {
|
||||
if (prevUserName && !store.getState().user.name) {
|
||||
logoutUser();
|
||||
}
|
||||
prevUserName = store.getState().user.name;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user