Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ios magic links handling #1034

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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