Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
5 changes: 4 additions & 1 deletion modules/hybrid-app/ios/ReactNativeHybridApp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about creating a template for those logs, method name could be a parameter🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for Android and web

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could even create single template on JS side and print those logs based on isHybridApp value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mateuuszzzzz agree, but I'd do that in separate PR in case of reverts

}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
Expand Down
1 change: 1 addition & 0 deletions modules/hybrid-app/src/NativeReactNativeHybridApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Spec>('ReactNativeHybridApp');
3 changes: 3 additions & 0 deletions modules/hybrid-app/src/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions modules/hybrid-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions modules/hybrid-app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 9 additions & 4 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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});
}
},
});

Expand Down Expand Up @@ -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});
}

/**
Expand All @@ -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);
}

Expand Down