Skip to content

Commit 9ba994f

Browse files
committed
chore: ID-3373: latest magic SDK internally checks for iframe so lazy loading no longer required.
1 parent 9b50dd5 commit 9ba994f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/passport/sdk/src/magic/magicAdapter.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Flow, trackDuration } from '@imtbl/metrics';
44
import { Eip1193Provider } from 'ethers';
55
import { PassportErrorType, withPassportError } from '../errors/passportError';
66
import { PassportConfiguration } from '../config';
7-
import { lazyDocumentReady } from '../utils/lazyLoad';
87
import { withMetricsAsync } from '../utils/metrics';
98
import { MagicProviderProxyFactory } from './magicProviderProxyFactory';
109
import { MagicClient } from './types';
@@ -16,29 +15,26 @@ export default class MagicAdapter {
1615

1716
private readonly magicProviderProxyFactory: MagicProviderProxyFactory;
1817

19-
private readonly lazyMagicClient?: Promise<MagicClient>;
18+
private readonly magicClient?: MagicClient;
2019

2120
constructor(config: PassportConfiguration, magicProviderProxyFactory: MagicProviderProxyFactory) {
2221
this.config = config;
2322
this.magicProviderProxyFactory = magicProviderProxyFactory;
2423

2524
if (typeof window !== 'undefined') {
26-
this.lazyMagicClient = lazyDocumentReady<MagicClient>(() => {
27-
const client = new Magic(this.config.magicPublishableApiKey, {
28-
extensions: [new OpenIdExtension()],
29-
network: MAINNET, // We always connect to mainnet to ensure addresses are the same across envs
30-
});
31-
return client;
25+
this.magicClient = new Magic(this.config.magicPublishableApiKey, {
26+
extensions: [new OpenIdExtension()],
27+
network: MAINNET, // We always connect to mainnet to ensure addresses are the same across envs
3228
});
3329
}
3430
}
3531

36-
private get magicClient(): Promise<MagicClient> {
37-
if (!this.lazyMagicClient) {
32+
private getMagicClient(): MagicClient {
33+
if (!this.magicClient) {
3834
throw new Error('Cannot perform this action outside of the browser');
3935
}
4036

41-
return this.lazyMagicClient;
37+
return this.magicClient;
4238
}
4339

4440
async login(
@@ -48,7 +44,7 @@ export default class MagicAdapter {
4844
withMetricsAsync(async (flow: Flow) => {
4945
const startTime = performance.now();
5046

51-
const magicClient = await this.magicClient;
47+
const magicClient = this.getMagicClient();
5248
flow.addEvent('endMagicClientInit');
5349

5450
await magicClient.openid.loginWithOIDC({
@@ -69,7 +65,7 @@ export default class MagicAdapter {
6965
}
7066

7167
async logout() {
72-
const magicClient = await this.magicClient;
68+
const magicClient = this.getMagicClient();
7369
if (magicClient.user) {
7470
await magicClient.user.logout();
7571
}

0 commit comments

Comments
 (0)