Skip to content

Commit

Permalink
fix: ios magic links handling (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmathew92 authored Jan 29, 2025
2 parents 56267bb + 17a8fc8 commit dc8a16f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
22 changes: 6 additions & 16 deletions src/webauth/__tests__/agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,10 @@ describe('Agent', () => {
});
});

describe('handle app linking for SFSafariViewController', () => {
it('with useSFSafariViewController AppLinking should be enabled', async () => {
await agent.login({}, { safariViewControllerPresentationStyle: 0 });
expect(Linking.addEventListener).toHaveBeenCalledTimes(1);
});

it('without useSFSafariViewController AppLinking should be enabled', async () => {
await agent.login({}, {});
expect(Linking.addEventListener).toHaveBeenCalledTimes(0);
});

describe('handle app linking for ios platform', () => {
it('for only iOS platform AppLinking should be enabled', async () => {
Platform.OS = 'android';
await agent.login({}, { safariViewControllerPresentationStyle: 0 });
await agent.login({}, {});
expect(Linking.addEventListener).toHaveBeenCalledTimes(0);
Platform.OS = 'ios'; //reset value to ios
});
Expand All @@ -339,9 +329,9 @@ describe('Agent', () => {
throw Error('123123');
});
try {
await agent.login({}, { safariViewControllerPresentationStyle: 0 });
await agent.login({}, {});
} catch (e) {}
expect(Linking.addEventListener).toHaveBeenCalledTimes(1);
!expect(Linking.addEventListener).toHaveBeenCalled;
expect(mockSubscription.remove).toHaveBeenCalledTimes(1);
});

Expand Down Expand Up @@ -393,8 +383,8 @@ describe('Agent', () => {
try {
await agent.login({}, {});
} catch (e) {}
expect(Linking.addEventListener).toHaveBeenCalledTimes(0);
expect(mockSubscription.remove).toHaveBeenCalledTimes(0);
!expect(Linking.addEventListener).toHaveBeenCalled();
!expect(mockSubscription.remove).toHaveBeenCalled();
});
});
});
5 changes: 1 addition & 4 deletions src/webauth/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ class Agent {
);
}
return new Promise(async (resolve, reject) => {
if (
Platform.OS === 'ios' &&
options.safariViewControllerPresentationStyle !== undefined
) {
if (Platform.OS === 'ios') {
linkSubscription = Linking.addEventListener('url', async (event) => {
try {
linkSubscription?.remove();
Expand Down

0 comments on commit dc8a16f

Please sign in to comment.