Skip to content

Commit

Permalink
Merge pull request #441 from auth0/fix-agent-link-warning
Browse files Browse the repository at this point in the history
Fix: Warning on RN65 while linking from agent.js
  • Loading branch information
poovamraj authored Jan 3, 2022
2 parents 965ef81 + 6ee2b20 commit 667e5ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/webauth/__mocks__/linking.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import EventEmitter from 'events';

class CustomEmitter extends EventEmitter {}
class CustomEmitter extends EventEmitter {
remove() {
this.removeAllListeners();
}
}

export default class Linking {
constructor() {
this.emitter = new CustomEmitter();
}

addEventListener(event, fn) {
this.emitter.addListener(event, fn);
return this.emitter.addListener(event, fn);
}

removeEventListener(event, fn) {
Expand Down
13 changes: 10 additions & 3 deletions src/webauth/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ export default class Agent {
}

return new Promise((resolve, reject) => {
let eventURL;
const urlHandler = event => {
NativeModules.A0Auth0.hide();
Linking.removeEventListener('url', urlHandler);
if (!skipLegacyListener) {
eventURL.remove();
}
resolve(event.url);
};
const params =
Platform.OS === 'ios' ? [ephemeralSession, closeOnLoad] : [closeOnLoad];
if (!skipLegacyListener) Linking.addEventListener('url', urlHandler);
if (!skipLegacyListener) {
eventURL = Linking.addEventListener('url', urlHandler);
}
NativeModules.A0Auth0.showUrl(url, ...params, (error, redirectURL) => {
if (!skipLegacyListener) Linking.removeEventListener('url', urlHandler);
if (!skipLegacyListener) {
eventURL.remove();
}
if (error) {
reject(error);
} else if (redirectURL) {
Expand Down

0 comments on commit 667e5ca

Please sign in to comment.