Skip to content

Commit

Permalink
Fix - Provide backward compatibility to remove event subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj committed Jan 7, 2022
1 parent 667e5ca commit 5418b4a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/webauth/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ export default class Agent {

return new Promise((resolve, reject) => {
let eventURL;
const removeListener = () => {
//This is done to handle backward compatibility with RN <= 0.64 which doesn't return EmitterSubscription on addEventListener
if (eventURL === undefined) {
Linking.removeEventListener('url', urlHandler);
} else {
eventURL.remove();
}
};
const urlHandler = event => {
NativeModules.A0Auth0.hide();
if (!skipLegacyListener) {
eventURL.remove();
removeListener();
}
resolve(event.url);
};
Expand All @@ -31,7 +39,7 @@ export default class Agent {
}
NativeModules.A0Auth0.showUrl(url, ...params, (error, redirectURL) => {
if (!skipLegacyListener) {
eventURL.remove();
removeListener();
}
if (error) {
reject(error);
Expand Down

0 comments on commit 5418b4a

Please sign in to comment.