Skip to content

Commit 30a1c5d

Browse files
[SDK] fix: Auto-connection of in-app wallets in React Native
1 parent 8b46952 commit 30a1c5d

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

.changeset/soft-camels-beg.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix autoconnection of inapp wallets in react native

packages/thirdweb/src/wallets/connection/autoConnectCore.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ export const autoConnectCore = async ({
5555
getStoredActiveWalletId(storage),
5656
]);
5757

58-
const { authResult, walletId, authProvider, authCookie } = getUrlToken();
59-
const wallet = wallets.find((w) => w.id === walletId);
58+
const result = getUrlToken();
6059

6160
// If an auth cookie is found and this site supports the wallet, we'll set the auth cookie in the client storage
62-
if (authCookie && wallet) {
61+
const wallet = wallets.find((w) => w.id === result?.walletId);
62+
if (result?.authCookie && wallet) {
6363
const clientStorage = new ClientScopedStorage({
6464
storage,
6565
clientId: props.client.clientId,
@@ -70,17 +70,17 @@ export const autoConnectCore = async ({
7070
}
7171
: undefined,
7272
});
73-
await clientStorage.saveAuthCookie(authCookie);
73+
await clientStorage.saveAuthCookie(result.authCookie);
7474
}
75-
76-
if (walletId) {
77-
lastActiveWalletId = walletId;
78-
lastConnectedWalletIds = lastConnectedWalletIds?.includes(walletId)
75+
if (result?.walletId) {
76+
lastActiveWalletId = result.walletId;
77+
lastConnectedWalletIds = lastConnectedWalletIds?.includes(result.walletId)
7978
? lastConnectedWalletIds
80-
: [walletId, ...(lastConnectedWalletIds || [])];
79+
: [result.walletId, ...(lastConnectedWalletIds || [])];
8180
}
82-
if (authProvider) {
83-
await setLastAuthProvider?.(authProvider, storage);
81+
82+
if (result?.authProvider) {
83+
await setLastAuthProvider?.(result.authProvider, storage);
8484
}
8585

8686
// if no wallets were last connected or we didn't receive an auth token
@@ -105,7 +105,7 @@ export const autoConnectCore = async ({
105105
wallet: activeWallet,
106106
client: props.client,
107107
lastConnectedChain,
108-
authResult,
108+
authResult: result?.authResult,
109109
}),
110110
{
111111
ms: timeout,
@@ -156,7 +156,7 @@ export const autoConnectCore = async ({
156156
wallet,
157157
client: props.client,
158158
lastConnectedChain,
159-
authResult,
159+
authResult: result?.authResult,
160160
});
161161
manager.addConnectedWallet(wallet);
162162
} catch {

packages/thirdweb/src/wallets/in-app/web/lib/get-url-token.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import type { AuthStoredTokenWithCookieReturnType } from "../../core/authenticat
55
/**
66
* Checks for an auth token and associated metadata in the current URL
77
*/
8-
export function getUrlToken(): {
9-
walletId?: WalletId;
10-
authResult?: AuthStoredTokenWithCookieReturnType;
11-
authProvider?: AuthOption;
12-
authCookie?: string;
13-
} {
14-
if (typeof window === "undefined") {
8+
export function getUrlToken():
9+
| {
10+
walletId?: WalletId;
11+
authResult?: AuthStoredTokenWithCookieReturnType;
12+
authProvider?: AuthOption;
13+
authCookie?: string;
14+
}
15+
| undefined {
16+
if (typeof document === "undefined") {
1517
// Not in web
16-
return {};
18+
return undefined;
1719
}
1820

1921
const queryString = window.location.search;
@@ -40,5 +42,5 @@ export function getUrlToken(): {
4042
);
4143
return { walletId, authResult, authProvider, authCookie };
4244
}
43-
return {};
45+
return undefined;
4446
}

0 commit comments

Comments
 (0)