Skip to content

Commit 5a1f394

Browse files
[SDK] fix: Prevent popup when using auth redirect mode
1 parent 880148b commit 5a1f394

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

.changeset/gold-meals-prove.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+
Prevent popup opening when logging in with auth mode: "redirect"

apps/playground-web/src/app/connect/in-app-wallet/page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ function AnyAuth() {
8080
limits on customizations and auth methods.
8181
</p>
8282
<CodeExample
83-
preview={
84-
<div className="w-1/2">
85-
<CustomLoginForm />
86-
</div>
87-
}
83+
preview={<CustomLoginForm />}
8884
code={`import { useState } from "react";
8985
import { useConnect } from "thirdweb/react";
9086
import { inAppWallet, preAuthenticate } from "thirdweb/wallets/in-app";

apps/playground-web/src/components/in-app-wallet/custom-login-form.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ export function CustomLoginForm() {
2727
const wallet = inAppWallet();
2828
await wallet.connect({
2929
strategy: "email",
30-
client: THIRDWEB_CLIENT,
3130
email,
3231
verificationCode,
32+
client: THIRDWEB_CLIENT,
33+
});
34+
return wallet;
35+
});
36+
};
37+
38+
const loginWithGoogle = async () => {
39+
connect(async () => {
40+
const wallet = inAppWallet({
41+
auth: {
42+
mode: "redirect",
43+
redirectUrl: `${window.location.origin}/connect/in-app-wallet`,
44+
},
45+
});
46+
await wallet.connect({
47+
strategy: "google",
48+
client: THIRDWEB_CLIENT,
3349
});
3450
return wallet;
3551
});
@@ -41,7 +57,7 @@ export function CustomLoginForm() {
4157

4258
if (screen === "login") {
4359
return (
44-
<div className="flex flex-col space-y-2">
60+
<div className="flex w-full flex-col space-y-4">
4561
<label htmlFor="email" className="font-medium text-sm">
4662
Email Address
4763
</label>
@@ -62,6 +78,14 @@ export function CustomLoginForm() {
6278
>
6379
{isConnecting ? "Submitting..." : "Submit"}
6480
</button>
81+
<p className="text-center text-sm text-white">Or</p>
82+
<button
83+
type="button"
84+
onClick={loginWithGoogle}
85+
className="rounded-lg bg-blue-500 px-4 py-2 text-white transition-colors enabled:hover:bg-blue-600"
86+
>
87+
Login with Google
88+
</button>
6589
{error && <p className="max-w-[300px] text-red-500">{error.message}</p>}
6690
</div>
6791
);

packages/thirdweb/src/wallets/in-app/core/interfaces/connector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface InAppConnector {
2121
strategy: SocialAuthOption,
2222
mode?: "redirect" | "popup" | "window",
2323
redirectUrl?: string,
24-
): void;
24+
): Promise<void>;
2525
// Login takes an auth token and connects a user with it
2626
loginWithAuthToken?(
2727
authResult: AuthStoredTokenWithCookieReturnType,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function connectInAppWallet(
4646
) {
4747
const strategy = options.strategy;
4848
if (socialAuthOptions.includes(strategy as SocialAuthOption)) {
49-
connector.authenticateWithRedirect(
49+
await connector.authenticateWithRedirect(
5050
strategy as SocialAuthOption,
5151
createOptions?.auth?.mode,
5252
createOptions?.auth?.redirectUrl,

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ const closeWindow = ({
2626
}
2727
};
2828

29-
export const loginWithOauthRedirect = (options: {
29+
export async function loginWithOauthRedirect(options: {
3030
authOption: OAuthOption;
3131
client: ThirdwebClient;
3232
ecosystem?: Ecosystem;
3333
redirectUrl?: string;
3434
mode?: "redirect" | "popup" | "window";
35-
}): void => {
35+
}): Promise<void> {
3636
const loginUrl = getLoginUrl({
3737
...options,
3838
mode: options.mode || "redirect",
@@ -42,7 +42,10 @@ export const loginWithOauthRedirect = (options: {
4242
} else {
4343
window.open(loginUrl);
4444
}
45-
};
45+
// wait for 5 secs for the redirect to happen
46+
// that way it interrupts the rest of the execution that would normally keep connecting
47+
await new Promise((resolve) => setTimeout(resolve, 5000));
48+
}
4649

4750
export const loginWithOauth = async (options: {
4851
authOption: OAuthOption;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ export class InAppWebConnector implements InAppConnector {
260260
});
261261
}
262262

263-
authenticateWithRedirect(
263+
async authenticateWithRedirect(
264264
strategy: SocialAuthOption,
265265
mode?: "redirect" | "popup" | "window",
266266
redirectUrl?: string,
267-
): void {
268-
loginWithOauthRedirect({
267+
): Promise<void> {
268+
return loginWithOauthRedirect({
269269
authOption: strategy,
270270
client: this.client,
271271
ecosystem: this.ecosystem,

0 commit comments

Comments
 (0)