@@ -20,7 +20,7 @@ function isMacOSWeb(): boolean {
20
20
return ! isMobile ( ) && typeof navigator === 'object' && typeof navigator . userAgent === 'string' && / M a c / i. test ( navigator . userAgent ) && ! / E l e c t r o n / i. test ( navigator . userAgent ) ;
21
21
}
22
22
23
- function promptToOpenInDesktopApp ( initialUrl = '' ) {
23
+ function promptToOpenInDesktopApp ( currentUserAccountID ?: number , initialUrl = '' ) {
24
24
// If the current url path is /transition..., meaning it was opened from oldDot, during this transition period:
25
25
// 1. The user session may not exist, because sign-in has not been completed yet.
26
26
// 2. There may be non-idempotent operations (e.g. create a new workspace), which obviously should not be executed again in the desktop app.
@@ -35,16 +35,24 @@ function promptToOpenInDesktopApp(initialUrl = '') {
35
35
} else {
36
36
// Match any magic link (/v/<account id>/<6 digit code>)
37
37
const isMagicLink = CONST . REGEX . ROUTES . VALIDATE_LOGIN . test ( window . location . pathname ) ;
38
+ const shouldAuthenticateWithCurrentAccount = ! isMagicLink || ( isMagicLink && ! ! currentUserAccountID && window . location . pathname . includes ( currentUserAccountID . toString ( ) ) ) ;
38
39
39
- beginDeepLinkRedirect ( ! isMagicLink , getInternalNewExpensifyPath ( initialUrl ) ) ;
40
+ beginDeepLinkRedirect ( shouldAuthenticateWithCurrentAccount , isMagicLink , getInternalNewExpensifyPath ( initialUrl ) ) ;
40
41
}
41
42
}
42
43
43
44
function DeeplinkWrapper ( { children, isAuthenticated, autoAuthState, initialUrl} : DeeplinkWrapperProps ) {
44
45
const [ currentScreen , setCurrentScreen ] = useState < string | undefined > ( ) ;
45
46
const [ hasShownPrompt , setHasShownPrompt ] = useState ( false ) ;
46
47
const removeListener = useRef < ( ) => void > ( ) ;
47
- const [ isActingAsDelegate ] = useOnyx ( ONYXKEYS . ACCOUNT , { selector : ( account ) => ! ! account ?. delegatedAccess ?. delegate } ) ;
48
+ const [ isActingAsDelegate ] = useOnyx ( ONYXKEYS . ACCOUNT , {
49
+ selector : ( account ) => ! ! account ?. delegatedAccess ?. delegate ,
50
+ canBeMissing : true ,
51
+ } ) ;
52
+ const [ currentUserAccountID ] = useOnyx ( ONYXKEYS . SESSION , {
53
+ selector : ( session ) => session ?. accountID ,
54
+ canBeMissing : true ,
55
+ } ) ;
48
56
const isActingAsDelegateRef = useRef ( isActingAsDelegate ) ;
49
57
const delegatorEmailRef = useRef ( getSearchParamFromUrl ( getCurrentUrl ( ) , 'delegatorEmail' ) ) ;
50
58
@@ -95,7 +103,7 @@ function DeeplinkWrapper({children, isAuthenticated, autoAuthState, initialUrl}:
95
103
// Otherwise, we want to wait until the navigation state is set up
96
104
// and we know the user is on a screen that supports deeplinks.
97
105
if ( isAuthenticated ) {
98
- promptToOpenInDesktopApp ( initialUrl ) ;
106
+ promptToOpenInDesktopApp ( currentUserAccountID , initialUrl ) ;
99
107
setHasShownPrompt ( true ) ;
100
108
} else {
101
109
// Navigation state is not set up yet, we're unsure if we should show the deep link prompt or not
@@ -111,7 +119,7 @@ function DeeplinkWrapper({children, isAuthenticated, autoAuthState, initialUrl}:
111
119
promptToOpenInDesktopApp ( ) ;
112
120
setHasShownPrompt ( true ) ;
113
121
}
114
- } , [ currentScreen , hasShownPrompt , isAuthenticated , autoAuthState , initialUrl ] ) ;
122
+ } , [ currentScreen , hasShownPrompt , isAuthenticated , autoAuthState , initialUrl , currentUserAccountID ] ) ;
115
123
116
124
return children ;
117
125
}
0 commit comments