Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back some HybridApp logic after TS migration to fix authentication #36750

Merged
merged 16 commits into from
Mar 19, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/pages/LogOutPreviousUserPage.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect} from 'react';
import {Linking} from 'react-native';
import React, {useContext, useEffect} from 'react';
import {Linking, NativeModules} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import InitialUrlContext from '@libs/InitialUrlContext';
import * as SessionUtils from '@libs/SessionUtils';
import Navigation from '@navigation/Navigation';
import type {AuthScreensParamList} from '@navigation/types';
import * as SessionActions from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Session} from '@src/types/onyx';
import type {Account, Session} from '@src/types/onyx';

type LogOutPreviousUserPageOnyxProps = {
/** The data about the current session which will be set once the user is authenticated and we return to this component as an AuthScreen */
session: OnyxEntry<Session>;
account: OnyxEntry<Account>;
};

type LogOutPreviousUserPageProps = LogOutPreviousUserPageOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSITION_BETWEEN_APPS>;
Expand All @@ -22,10 +28,12 @@ type LogOutPreviousUserPageProps = LogOutPreviousUserPageOnyxProps & StackScreen
// out if the transition is for another user.
//
// This component should not do any other navigation as that handled in App.setUpPoliciesAndNavigate
function LogOutPreviousUserPage({session, route}: LogOutPreviousUserPageProps) {
function LogOutPreviousUserPage({session, route, account}: LogOutPreviousUserPageProps) {
const initUrl = useContext(InitialUrlContext);
AndrewGable marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
Linking.getInitialURL().then((transitionURL) => {
Linking.getInitialURL().then((url) => {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
const sessionEmail = session?.email;
const transitionURL = NativeModules.HybridAppModule ? CONST.DEEPLINK_BASE_URL + initUrl : url;
AndrewGable marked this conversation as resolved.
Show resolved Hide resolved
const isLoggingInAsNewUser = SessionUtils.isLoggingInAsNewUser(transitionURL ?? undefined, sessionEmail);

if (isLoggingInAsNewUser) {
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -42,18 +50,28 @@ function LogOutPreviousUserPage({session, route}: LogOutPreviousUserPageProps) {
const shortLivedAuthToken = route.params.shortLivedAuthToken ?? '';
SessionActions.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
}
const exitTo = route.params.exitTo as Route | null;
// We don't want to navigate to the exitTo route when creating a new workspace from a deep link,
// because we already handle creating the optimistic policy and navigating to it in App.setUpPoliciesAndNavigate,
// which is already called when AuthScreens mounts.
if (exitTo && exitTo !== ROUTES.WORKSPACE_NEW && !account?.isLoading && !isLoggingInAsNewUser) {
Navigation.isNavigationReady().then(() => {
// remove this screen and navigate to exit route
const exitUrl = NativeModules.HybridAppModule ? Navigation.parseHybridAppUrl(exitTo) : exitTo;
Navigation.goBack();
Navigation.navigate(exitUrl);
});
}
});

// We only want to run this effect once on mount (when the page first loads after transitioning from OldDot)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [initUrl, account, route, session]);
roryabraham marked this conversation as resolved.
Show resolved Hide resolved

return <FullScreenLoadingIndicator />;
}

LogOutPreviousUserPage.displayName = 'LogOutPreviousUserPage';

export default withOnyx<LogOutPreviousUserPageProps, LogOutPreviousUserPageOnyxProps>({
account: {key: ONYXKEYS.ACCOUNT},
AndrewGable marked this conversation as resolved.
Show resolved Hide resolved
session: {
key: ONYXKEYS.SESSION,
},
Expand Down
Loading