Paste oauth token using deeplink
Reviewed By: passy Differential Revision: D28790868 fbshipit-source-id: 6a22809444462af15915fa4f06e76e64ebb7f590
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cf14f0808f
commit
fff489091e
@@ -8,7 +8,12 @@
|
||||
*/
|
||||
|
||||
import {remote, ipcRenderer, IpcRendererEvent} from 'electron';
|
||||
import {toggleAction} from '../reducers/application';
|
||||
import {
|
||||
ACTIVE_SHEET_SIGN_IN,
|
||||
setActiveSheet,
|
||||
setPastedToken,
|
||||
toggleAction,
|
||||
} from '../reducers/application';
|
||||
import {Group, SUPPORTED_GROUPS} from '../reducers/supportForm';
|
||||
import {Store} from '../reducers/index';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
@@ -20,7 +25,6 @@ import {
|
||||
} from '../utils/exportData';
|
||||
import {tryCatchReportPlatformFailures} from '../utils/metrics';
|
||||
import {selectPlugin} from '../reducers/connections';
|
||||
import qs from 'query-string';
|
||||
|
||||
export const uriComponents = (url: string): Array<string> => {
|
||||
if (!url) {
|
||||
@@ -74,9 +78,11 @@ export default (store: Store, _logger: Logger) => {
|
||||
'flipper-protocol-handler',
|
||||
(_event: IpcRendererEvent, query: string) => {
|
||||
const uri = new URL(query);
|
||||
if (query.startsWith('flipper://import')) {
|
||||
const {search} = new URL(query);
|
||||
const {url} = qs.parse(search);
|
||||
if (uri.protocol !== 'flipper:') {
|
||||
return;
|
||||
}
|
||||
if (uri.pathname.match(/^\/*import\/*$/)) {
|
||||
const url = uri.searchParams.get('url');
|
||||
store.dispatch(toggleAction('downloadingImportData', true));
|
||||
return (
|
||||
typeof url === 'string' &&
|
||||
@@ -91,16 +97,20 @@ export default (store: Store, _logger: Logger) => {
|
||||
store.dispatch(toggleAction('downloadingImportData', false));
|
||||
})
|
||||
);
|
||||
} else if (
|
||||
uri.protocol === 'flipper:' &&
|
||||
uri.pathname.includes('support-form')
|
||||
) {
|
||||
} else if (uri.pathname.match(/^\/*support-form\/*$/)) {
|
||||
const formParam = uri.searchParams.get('form');
|
||||
const grp = deeplinkFormParamToGroups(formParam);
|
||||
if (grp) {
|
||||
grp.handleSupportFormDeeplinks(store);
|
||||
}
|
||||
return;
|
||||
} else if (uri.pathname.match(/^\/*login\/*$/)) {
|
||||
const token = uri.searchParams.get('token');
|
||||
store.dispatch(setPastedToken(token ?? undefined));
|
||||
if (store.getState().application.activeSheet !== ACTIVE_SHEET_SIGN_IN) {
|
||||
store.dispatch(setActiveSheet(ACTIVE_SHEET_SIGN_IN));
|
||||
}
|
||||
return;
|
||||
}
|
||||
const match = uriComponents(query);
|
||||
if (match.length > 1) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {v1 as uuidv1} from 'uuid';
|
||||
import {ReactElement} from 'react';
|
||||
import CancellableExportStatus from '../chrome/CancellableExportStatus';
|
||||
import {Actions} from './';
|
||||
import produce from 'immer';
|
||||
export const ACTIVE_SHEET_PLUGIN_SHEET: 'PLUGIN_SHEET' = 'PLUGIN_SHEET';
|
||||
export const ACTIVE_SHEET_PLUGINS: 'PLUGINS' = 'PLUGINS';
|
||||
export const ACTIVE_SHEET_SELECT_PLUGINS_TO_EXPORT: 'SELECT_PLUGINS_TO_EXPORT' =
|
||||
@@ -87,6 +88,7 @@ export type State = {
|
||||
launcherMsg: LauncherMsg;
|
||||
statusMessages: Array<string>;
|
||||
xcodeCommandLineToolsDetected: boolean;
|
||||
pastedToken?: string;
|
||||
};
|
||||
|
||||
type BooleanActionType =
|
||||
@@ -154,6 +156,10 @@ export type Action =
|
||||
payload: {
|
||||
isDetected: boolean;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: 'SET_PASTED_TOKEN';
|
||||
payload?: string;
|
||||
};
|
||||
|
||||
export const initialState: () => State = () => ({
|
||||
@@ -288,6 +294,10 @@ export default function reducer(
|
||||
return state;
|
||||
} else if (action.type === 'SET_XCODE_DETECTED') {
|
||||
return {...state, xcodeCommandLineToolsDetected: action.payload.isDetected};
|
||||
} else if (action.type === 'SET_PASTED_TOKEN') {
|
||||
return produce(state, (draft) => {
|
||||
draft.pastedToken = action.payload;
|
||||
});
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
@@ -366,3 +376,8 @@ export const setXcodeDetected = (isDetected: boolean): Action => ({
|
||||
type: 'SET_XCODE_DETECTED',
|
||||
payload: {isDetected},
|
||||
});
|
||||
|
||||
export const setPastedToken = (pastedToken?: string): Action => ({
|
||||
type: 'SET_PASTED_TOKEN',
|
||||
payload: pastedToken,
|
||||
});
|
||||
|
||||
@@ -31,6 +31,7 @@ import {SidebarLeft, SidebarRight} from './SandyIcons';
|
||||
import {useDispatch, useStore} from '../utils/useStore';
|
||||
import {
|
||||
ACTIVE_SHEET_PLUGINS,
|
||||
ACTIVE_SHEET_SIGN_IN,
|
||||
setActiveSheet,
|
||||
toggleLeftSidebarVisible,
|
||||
toggleRightSidebarVisible,
|
||||
@@ -39,7 +40,6 @@ import {theme, Layout, withTrackingScope} from 'flipper-plugin';
|
||||
import SetupDoctorScreen, {checkHasNewProblem} from './SetupDoctorScreen';
|
||||
import SettingsSheet from '../chrome/SettingsSheet';
|
||||
import WelcomeScreen from './WelcomeScreen';
|
||||
import SignInSheet from '../chrome/fb-stubs/SignInSheet';
|
||||
import {errorCounterAtom} from '../chrome/ConsoleLogs';
|
||||
import {ToplevelProps} from './SandyApp';
|
||||
import {useValue} from 'flipper-plugin';
|
||||
@@ -370,9 +370,10 @@ function LoginButton() {
|
||||
const user = useStore((state) => state.user);
|
||||
const login = (user?.id ?? null) !== null;
|
||||
const profileUrl = user?.profile_picture?.uri;
|
||||
const [showLogin, setShowLogin] = useState(false);
|
||||
const showLogin = useCallback(() => {
|
||||
dispatch(setActiveSheet(ACTIVE_SHEET_SIGN_IN));
|
||||
}, [dispatch]);
|
||||
const [showLogout, setShowLogout] = useState(false);
|
||||
const onClose = useCallback(() => setShowLogin(false), []);
|
||||
const onHandleVisibleChange = useCallback(
|
||||
(visible) => setShowLogout(visible),
|
||||
[],
|
||||
@@ -385,10 +386,11 @@ function LoginButton() {
|
||||
error instanceof UserUnauthorizedError ||
|
||||
error instanceof UserNotSignedInError
|
||||
) {
|
||||
setShowLogin(true);
|
||||
showLogin();
|
||||
}
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return login ? (
|
||||
@@ -418,9 +420,8 @@ function LoginButton() {
|
||||
<LeftRailButton
|
||||
icon={<LoginOutlined />}
|
||||
title="Log In"
|
||||
onClick={() => setShowLogin(true)}
|
||||
onClick={showLogin}
|
||||
/>
|
||||
{showLogin && <SignInSheet onHide={onClose} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user