diff --git a/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt b/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt index da3f745f4564..9521bcf725a7 100644 --- a/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt +++ b/modules/hybrid-app/android/src/main/java/com/expensify/reactnativehybridapp/ReactNativeHybridApp.kt @@ -28,4 +28,8 @@ class ReactNativeHybridApp(reactContext: ReactApplicationContext) : ) { Log.d(NAME, "`switchAccount` should never be called in standalone `New Expensify` app") } + + override fun sendAuthToken(authToken: String?) { + Log.d(NAME, "`sendAuthToken` should never be called in standalone `New Expensify` app") + } } diff --git a/modules/hybrid-app/ios/ReactNativeHybridApp.mm b/modules/hybrid-app/ios/ReactNativeHybridApp.mm index 8b55a73be5a3..1b2183593de6 100644 --- a/modules/hybrid-app/ios/ReactNativeHybridApp.mm +++ b/modules/hybrid-app/ios/ReactNativeHybridApp.mm @@ -13,13 +13,16 @@ - (void)closeReactNativeApp:(BOOL)shouldSignOut shouldSetNVP:(BOOL)shouldSetNVP - (void)completeOnboarding:(BOOL)status { NSLog(@"[ReactNativeHybridApp] `completeOnboarding` should never be called in standalone `New Expensify` app"); - } - (void)switchAccount:(NSString *)newDotCurrentAccountEmail authToken:(NSString *)authToken policyID:(NSString *)policyID accountID:(NSString *)accountID { NSLog(@"[ReactNativeHybridApp] `switchAccount` should never be called in standalone `New Expensify` app"); } +- (void)sendAuthToken:(NSString *)authToken { + NSLog(@"[ReactNativeHybridApp] `sendAuthToken` should never be called in standalone `New Expensify` app"); +} + - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { diff --git a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts index f9041c557717..ec346c56248c 100644 --- a/modules/hybrid-app/src/NativeReactNativeHybridApp.ts +++ b/modules/hybrid-app/src/NativeReactNativeHybridApp.ts @@ -7,6 +7,7 @@ export interface Spec extends TurboModule { closeReactNativeApp: (shouldSignOut: boolean, shouldSetNVP: boolean) => void; completeOnboarding: (status: boolean) => void; switchAccount: (newDotCurrentAccountEmail: string, authToken: string, policyID: string, accountID: string) => void; + sendAuthToken: (authToken: string) => void; } export default TurboModuleRegistry.getEnforcing('ReactNativeHybridApp'); diff --git a/modules/hybrid-app/src/index.native.ts b/modules/hybrid-app/src/index.native.ts index 956cb5784dfc..6554307d0a00 100644 --- a/modules/hybrid-app/src/index.native.ts +++ b/modules/hybrid-app/src/index.native.ts @@ -14,6 +14,9 @@ const HybridAppModule: HybridAppModuleType = { switchAccount({newDotCurrentAccountEmail, authToken, policyID, accountID}) { ReactNativeHybridApp.switchAccount(newDotCurrentAccountEmail, authToken, policyID, accountID); }, + sendAuthToken({authToken}) { + ReactNativeHybridApp.sendAuthToken(authToken); + }, }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/index.ts b/modules/hybrid-app/src/index.ts index 6316ee8fb960..222771249e7d 100644 --- a/modules/hybrid-app/src/index.ts +++ b/modules/hybrid-app/src/index.ts @@ -16,6 +16,10 @@ const HybridAppModule: HybridAppModuleType = { // eslint-disable-next-line no-console console.warn('HybridAppModule: `switchAccount` should never be called on web'); }, + sendAuthToken() { + // eslint-disable-next-line no-console + console.warn('HybridAppModule: `sendAuthToken` should never be called on web'); + }, }; export default HybridAppModule; diff --git a/modules/hybrid-app/src/types.ts b/modules/hybrid-app/src/types.ts index 5fef691d3a48..9bd33a7c4ce8 100644 --- a/modules/hybrid-app/src/types.ts +++ b/modules/hybrid-app/src/types.ts @@ -3,6 +3,7 @@ type HybridAppModuleType = { closeReactNativeApp: (args: {shouldSignOut: boolean; shouldSetNVP: boolean}) => void; completeOnboarding: (args: {status: boolean}) => void; switchAccount: (args: {newDotCurrentAccountEmail: string; authToken: string; policyID: string; accountID: string}) => void; + sendAuthToken: (args: {authToken: string}) => void; }; export default HybridAppModuleType; diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index dc81842045a0..d3672c1464ef 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -62,6 +62,8 @@ import type {AutoAuthState} from '@src/types/onyx/Session'; import clearCache from './clearCache'; import updateSessionAuthTokens from './updateSessionAuthTokens'; +const INVALID_TOKEN = 'pizza'; + let session: Session = {}; let authPromiseResolver: ((value: boolean) => void) | null = null; Onyx.connect({ @@ -75,6 +77,9 @@ Onyx.connect({ authPromiseResolver(true); authPromiseResolver = null; } + if (CONFIG.IS_HYBRID_APP && session.authToken && session.authToken !== INVALID_TOKEN) { + HybridAppModule.sendAuthToken({authToken: session.authToken}); + } }, }); @@ -816,8 +821,8 @@ function invalidateCredentials() { } function invalidateAuthToken() { - NetworkStore.setAuthToken('pizza'); - Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza', encryptedAuthToken: 'pizza'}); + NetworkStore.setAuthToken(INVALID_TOKEN); + Onyx.merge(ONYXKEYS.SESSION, {authToken: INVALID_TOKEN, encryptedAuthToken: INVALID_TOKEN}); } /** @@ -826,8 +831,8 @@ function invalidateAuthToken() { function expireSessionWithDelay() { // expires the session after 15s setTimeout(() => { - NetworkStore.setAuthToken('pizza'); - Onyx.merge(ONYXKEYS.SESSION, {authToken: 'pizza', encryptedAuthToken: 'pizza', creationDate: new Date().getTime() - CONST.SESSION_EXPIRATION_TIME_MS}); + NetworkStore.setAuthToken(INVALID_TOKEN); + Onyx.merge(ONYXKEYS.SESSION, {authToken: INVALID_TOKEN, encryptedAuthToken: INVALID_TOKEN, creationDate: new Date().getTime() - CONST.SESSION_EXPIRATION_TIME_MS}); }, 15000); }