Skip to content

Commit 79260c8

Browse files
authored
Add new auth fields for redirect (#4099)
1 parent cf8badb commit 79260c8

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

.changeset/tidy-beds-heal.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+
Add new auth fields to support redirect in web and electron applications

packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ export const ConnectWalletSocialOptions = (
181181
authOption: strategy,
182182
client: props.client,
183183
ecosystem: ecosystemInfo,
184+
redirectUrl: walletConfig?.auth?.redirectUrl,
185+
redirectExternally: walletConfig?.auth?.redirectExternally,
184186
});
185187
}
186188

packages/thirdweb/src/react/web/wallets/shared/SocialLogin.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export function SocialLogin(props: {
6363
partnerId: wallet.getConfig()?.partnerId,
6464
}
6565
: undefined,
66+
redirectUrl: walletConfig?.auth?.redirectUrl,
67+
redirectExternally: walletConfig?.auth?.redirectExternally,
6668
});
6769
}
6870

packages/thirdweb/src/wallets/ecosystem/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type EcosystemWalletCreationOptions = {
77
partnerId?: string;
88
auth?: {
99
mode?: "popup" | "redirect";
10+
redirectUrl?: string;
11+
redirectExternally?: boolean;
1012
};
1113
};
1214

packages/thirdweb/src/wallets/in-app/core/wallet/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export type InAppWalletCreationOptions =
3737
* Whether to display the social auth prompt in a popup or redirect
3838
*/
3939
mode?: "popup" | "redirect";
40+
/**
41+
* Optional url to redirect to after authentication
42+
*/
43+
redirectUrl?: string;
44+
/**
45+
* Whether to handle the redirect in a new window
46+
*/
47+
redirectExternally?: boolean;
4048
/**
4149
* The domain of the passkey to use for authentication
4250
*/

packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ export const loginWithOauthRedirect = (options: {
3030
authOption: SocialAuthOption;
3131
client: ThirdwebClient;
3232
ecosystem?: Ecosystem;
33+
redirectUrl?: string;
34+
redirectExternally?: boolean;
3335
}): void => {
3436
const loginUrl = getLoginUrl({
3537
...options,
3638
mode: "redirect",
3739
});
38-
window.location.href = loginUrl;
40+
if (options.redirectExternally === true) {
41+
window.open(loginUrl);
42+
} else {
43+
window.location.href = loginUrl;
44+
}
3945
};
4046

4147
export const loginWithOauth = async (options: {

0 commit comments

Comments
 (0)