Skip to content

Commit

Permalink
Fix deeplinks don't work when signing in with a new account
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberAndrii committed Sep 21, 2024
1 parent 9160fa5 commit fe4d0ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2673,13 +2673,7 @@ function openReportFromDeepLink(url: string) {
Session.waitForUserSignIn().then(() => {
const connection = Onyx.connect({
key: ONYXKEYS.NVP_ONBOARDING,
callback: (onboarding) => {
if (onboarding) {
// Once the onboarding data is available, we want to disconnect the connection
// so it won't trigger the deeplink again every time the data is changed, for example, when relogin.
Onyx.disconnect(connection);
}

callback: () => {
Navigation.waitForProtectedRoutes().then(() => {
if (route && Session.isAnonymousUser() && !Session.canAnonymousUserAccessRoute(route)) {
Session.signOutAndRedirectToSignIn(true);
Expand All @@ -2696,7 +2690,15 @@ function openReportFromDeepLink(url: string) {
// We need skip deeplinking if the user hasn't completed the guided setup flow.
Welcome.isOnboardingFlowCompleted({
onNotCompleted: () => OnboardingFlow.startOnboardingFlow(),
onCompleted: () => {
onCompleted: (isOldDotAccount) => {
// We want to disconnect the connection so it won't trigger the deeplink again
// every time the data is changed, for example, when relogin.
Onyx.disconnect(connection);

if (isOldDotAccount) {
return;
}

const state = navigationRef.getRootState();
const currentFocusedRoute = findFocusedRoute(state);

Expand Down
17 changes: 13 additions & 4 deletions src/libs/actions/Welcome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let tryNewDotData: TryNewDot | undefined;
let onboarding: OnboardingData;

type HasCompletedOnboardingFlowProps = {
onCompleted?: () => void;
onCompleted?: (isOldDotAccount: boolean) => void;
onNotCompleted?: () => void;
};

Expand Down Expand Up @@ -52,14 +52,23 @@ function onServerDataReady(): Promise<void> {
let isOnboardingInProgress = false;
function isOnboardingFlowCompleted({onCompleted, onNotCompleted}: HasCompletedOnboardingFlowProps) {
isOnboardingFlowStatusKnownPromise.then(() => {
if (Array.isArray(onboarding) || onboarding?.hasCompletedGuidedSetupFlow === undefined) {
// onboarding is an array for old accounts and accounts created from olddot
if (Array.isArray(onboarding)) {
onCompleted?.(true);
return;
}

if (onboarding?.hasCompletedGuidedSetupFlow === undefined) {
return;
}

if (onboarding?.hasCompletedGuidedSetupFlow) {
isOnboardingInProgress = false;
onCompleted?.();
} else if (!isOnboardingInProgress) {
onCompleted?.(false);
return;
}

if (!isOnboardingInProgress) {
isOnboardingInProgress = true;
onNotCompleted?.();
}
Expand Down

0 comments on commit fe4d0ac

Please sign in to comment.