Skip to content

Commit

Permalink
fix(rtn-web-browser): signInWithRedirect needs to be called twice on …
Browse files Browse the repository at this point in the history
…Android

* fix(rtn-web-browser): signInWithRedirect needs to be called twice on Android

* chore: add code owner

* address feedback

* update codeowners

* update codeowners

* Update .github/CODEOWNERS

---------

Co-authored-by: Ashwin Kumar <ashwsrir@amazon.com>
  • Loading branch information
ashwinkumar6 and Ashwin Kumar authored Jul 23, 2024
1 parent 3d70792 commit b473ce3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/packages/core/src/clients/internal @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
/packages/core/src/Hub @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
/packages/adapter-nextjs @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
/packages/rtn-web-browser @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
/packages/storage/src/providers/s3/apis/internal @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
/packages/storage/src/providers/s3/apis/server @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
/packages/api-rest/src/apis/server.ts @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
Expand Down
34 changes: 22 additions & 12 deletions packages/rtn-web-browser/src/apis/openAuthSessionAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,44 @@ const openAuthSessionAndroid = async (url: string, redirectUrls: string[]) => {

return redirectUrl;
} finally {
appStateListener?.remove();
redirectListener?.remove();
appStateListener = undefined;
redirectListener = undefined;
removeAppStateListener();
removeRedirectListener();
}
};

const getAppStatePromise = (): Promise<null> =>
new Promise(resolve => {
appStateListener = AppState.addEventListener('change', nextAppState => {
// if current state is null, the change is from initialization
if (AppState.currentState === null) {
return;
}
// remove any stray listeners before creating new ones
removeAppStateListener();

if (nextAppState === 'active') {
appStateListener?.remove();
appStateListener = undefined;
let previousState = AppState.currentState;
appStateListener = AppState.addEventListener('change', nextAppState => {
if (previousState !== 'active' && nextAppState === 'active') {
removeAppStateListener();
resolve(null);
}
previousState = nextAppState;
});
});

const getRedirectPromise = (redirectUrls: string[]): Promise<string> =>
new Promise(resolve => {
// remove any stray listeners before creating new ones
removeRedirectListener();

redirectListener = Linking.addEventListener('url', event => {
if (redirectUrls.some(url => event.url.startsWith(url))) {
resolve(event.url);
}
});
});

const removeAppStateListener = () => {
appStateListener?.remove();
appStateListener = undefined;
};

const removeRedirectListener = () => {
redirectListener?.remove();
redirectListener = undefined;
};

0 comments on commit b473ce3

Please sign in to comment.