Skip to content

Commit b473ce3

Browse files
ashwinkumar6Ashwin Kumar
and
Ashwin Kumar
authored
fix(rtn-web-browser): signInWithRedirect needs to be called twice on 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 <[email protected]>
1 parent 3d70792 commit b473ce3

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/packages/core/src/clients/internal @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
2828
/packages/core/src/Hub @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
2929
/packages/adapter-nextjs @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
30+
/packages/rtn-web-browser @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
3031
/packages/storage/src/providers/s3/apis/internal @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
3132
/packages/storage/src/providers/s3/apis/server @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF
3233
/packages/api-rest/src/apis/server.ts @ukhan-amazon @haverchuck @cshfang @jimblanc @HuiSF

packages/rtn-web-browser/src/apis/openAuthSessionAsync.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,34 +61,44 @@ const openAuthSessionAndroid = async (url: string, redirectUrls: string[]) => {
6161

6262
return redirectUrl;
6363
} finally {
64-
appStateListener?.remove();
65-
redirectListener?.remove();
66-
appStateListener = undefined;
67-
redirectListener = undefined;
64+
removeAppStateListener();
65+
removeRedirectListener();
6866
}
6967
};
7068

7169
const getAppStatePromise = (): Promise<null> =>
7270
new Promise(resolve => {
73-
appStateListener = AppState.addEventListener('change', nextAppState => {
74-
// if current state is null, the change is from initialization
75-
if (AppState.currentState === null) {
76-
return;
77-
}
71+
// remove any stray listeners before creating new ones
72+
removeAppStateListener();
7873

79-
if (nextAppState === 'active') {
80-
appStateListener?.remove();
81-
appStateListener = undefined;
74+
let previousState = AppState.currentState;
75+
appStateListener = AppState.addEventListener('change', nextAppState => {
76+
if (previousState !== 'active' && nextAppState === 'active') {
77+
removeAppStateListener();
8278
resolve(null);
8379
}
80+
previousState = nextAppState;
8481
});
8582
});
8683

8784
const getRedirectPromise = (redirectUrls: string[]): Promise<string> =>
8885
new Promise(resolve => {
86+
// remove any stray listeners before creating new ones
87+
removeRedirectListener();
88+
8989
redirectListener = Linking.addEventListener('url', event => {
9090
if (redirectUrls.some(url => event.url.startsWith(url))) {
9191
resolve(event.url);
9292
}
9393
});
9494
});
95+
96+
const removeAppStateListener = () => {
97+
appStateListener?.remove();
98+
appStateListener = undefined;
99+
};
100+
101+
const removeRedirectListener = () => {
102+
redirectListener?.remove();
103+
redirectListener = undefined;
104+
};

0 commit comments

Comments
 (0)