Skip to content

Commit

Permalink
Merge pull request #45 from akropolisio/DD-3082-add-unstoppable-domai…
Browse files Browse the repository at this point in the history
…ns-connector

fix: [DD-3082] Fix unstoppable login on page refresh
  • Loading branch information
in19farkt authored Feb 16, 2022
2 parents ccf5de0 + c5a6ce4 commit 45b8a1b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/unstoppable-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ export class UnstoppableConnector extends AbstractConnector<UnstoppableConnectio
const UAuth = (await import('@uauth/js')).default;
const uauth = new UAuth(clientOptions);

await uauth.loginWithPopup(loginOptions, popupConfig);
const { provider, subConnector, user } = await this.activateSubConnector(uauth);
let user: UserInfo | null = null;

try {
user = await uauth.user();
} catch {
if (!uauth.fallbackLoginOptions.scope.includes('wallet')) {
throw new Error('Must request the "wallet" scope for connector to work.');
}

await uauth.loginWithPopup(loginOptions, popupConfig);
user = await uauth.user();
}

const { provider, subConnector } = await this.activateSubConnector(user);

this.payload = { uauth, provider, subConnector, user };

Expand Down Expand Up @@ -101,9 +113,7 @@ export class UnstoppableConnector extends AbstractConnector<UnstoppableConnectio
return { unsubscribe: () => subscriptions.forEach((s) => s.unsubscribe()) };
}

private async activateSubConnector(uauth: UAuthClass) {
const user = await uauth.user();

private async activateSubConnector(user: UserInfo) {
if (!user.wallet_type_hint) {
throw new Error('No wallet type present');
}
Expand All @@ -120,6 +130,6 @@ export class UnstoppableConnector extends AbstractConnector<UnstoppableConnectio

const { provider } = await subConnector?.connect();

return { provider, subConnector, user };
return { provider, subConnector };
}
}

0 comments on commit 45b8a1b

Please sign in to comment.