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
59 lines
1019 B
TypeScript
59 lines
1019 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 {Actions} from './';
|
|
|
|
export const USER_UNAUTHORIZED = 'Unauthorized.';
|
|
export const USER_NOT_SIGNEDIN = 'Not signed in.';
|
|
|
|
export type User = {
|
|
name?: string;
|
|
profile_picture?: {
|
|
uri: string;
|
|
};
|
|
};
|
|
|
|
export type State = User;
|
|
|
|
export type Action =
|
|
| {
|
|
type: 'LOGIN';
|
|
payload: User;
|
|
}
|
|
| {
|
|
type: 'LOGOUT';
|
|
};
|
|
|
|
const INITIAL_STATE: State = {};
|
|
|
|
export default function reducer(
|
|
state: State = INITIAL_STATE,
|
|
action: Actions,
|
|
): State {
|
|
if (action.type === 'LOGOUT') {
|
|
return {};
|
|
} else if (action.type === 'LOGIN') {
|
|
return {
|
|
...state,
|
|
...action.payload,
|
|
};
|
|
} else {
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export const login = (payload: User): Action => ({
|
|
type: 'LOGIN',
|
|
payload,
|
|
});
|
|
|
|
export const logout = (): Action => ({
|
|
type: 'LOGOUT',
|
|
});
|