Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-meals-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Prevent popup opening when logging in with auth mode: "redirect"
22 changes: 15 additions & 7 deletions apps/playground-web/src/app/connect/in-app-wallet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,13 @@ function AnyAuth() {
limits on customizations and auth methods.
</p>
<CodeExample
preview={
<div className="w-1/2">
<CustomLoginForm />
</div>
}
preview={<CustomLoginForm />}
code={`import { useState } from "react";
import { useConnect } from "thirdweb/react";
import { inAppWallet, preAuthenticate } from "thirdweb/wallets/in-app";

const wallet = inAppWallet();

export function CustomLoginUi() {
const { connect, isConnecting, error } = useConnect();

Expand All @@ -101,10 +99,9 @@ export function CustomLoginUi() {
});
};

const handleLogin = async (email: string, verificationCode: string) => {
const loginWithEmail = async (email: string, verificationCode: string) => {
// verify email with verificationCode and connect
connect(async () => {
const wallet = inAppWallet();
await wallet.connect({
client,
strategy: "email",
Expand All @@ -114,6 +111,17 @@ export function CustomLoginUi() {
return wallet;
});
};

const loginWithGoogle = async () => {
// connect with google
connect(async () => {
await wallet.connect({
client,
strategy: "google",
});
return wallet;
});
};
}
`}
lang="tsx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,26 @@ export function CustomLoginForm() {
const wallet = inAppWallet();
await wallet.connect({
strategy: "email",
client: THIRDWEB_CLIENT,
email,
verificationCode,
client: THIRDWEB_CLIENT,
});
return wallet;
});
};

const loginWithGoogle = async () => {
connect(async () => {
const wallet = inAppWallet({
auth: {
options: ["google"],
mode: "redirect",
redirectUrl: `${window.location.origin}/connect/in-app-wallet`,
},
});
await wallet.connect({
strategy: "google",
client: THIRDWEB_CLIENT,
});
return wallet;
});
Expand All @@ -41,7 +58,7 @@ export function CustomLoginForm() {

if (screen === "login") {
return (
<div className="flex flex-col space-y-2">
<div className="flex w-full flex-col space-y-4">
<label htmlFor="email" className="font-medium text-sm">
Email Address
</label>
Expand All @@ -62,6 +79,14 @@ export function CustomLoginForm() {
>
{isConnecting ? "Submitting..." : "Submit"}
</button>
<p className="text-center text-sm text-white">Or</p>
<button
type="button"
onClick={loginWithGoogle}
className="rounded-lg bg-blue-500 px-4 py-2 text-white transition-colors enabled:hover:bg-blue-600"
>
Login with Google
</button>
{error && <p className="max-w-[300px] text-red-500">{error.message}</p>}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface InAppConnector {
strategy: SocialAuthOption,
mode?: "redirect" | "popup" | "window",
redirectUrl?: string,
): void;
): Promise<void>;
// Login takes an auth token and connects a user with it
loginWithAuthToken?(
authResult: AuthStoredTokenWithCookieReturnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
) {
const strategy = options.strategy;
if (socialAuthOptions.includes(strategy as SocialAuthOption)) {
connector.authenticateWithRedirect(
await connector.authenticateWithRedirect(

Check warning on line 49 in packages/thirdweb/src/wallets/in-app/core/wallet/index.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L49 was not covered by tests
strategy as SocialAuthOption,
createOptions?.auth?.mode,
createOptions?.auth?.redirectUrl,
Expand Down
9 changes: 6 additions & 3 deletions packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
}
};

export const loginWithOauthRedirect = (options: {
export async function loginWithOauthRedirect(options: {

Check warning on line 29 in packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L29 was not covered by tests
authOption: OAuthOption;
client: ThirdwebClient;
ecosystem?: Ecosystem;
redirectUrl?: string;
mode?: "redirect" | "popup" | "window";
}): void => {
}): Promise<void> {

Check warning on line 35 in packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L35 was not covered by tests
const loginUrl = getLoginUrl({
...options,
mode: options.mode || "redirect",
Expand All @@ -42,7 +42,10 @@
} else {
window.open(loginUrl);
}
};
// wait for 5 secs for the redirect to happen
// that way it interrupts the rest of the execution that would normally keep connecting
await new Promise((resolve) => setTimeout(resolve, 5000));
}

Check warning on line 48 in packages/thirdweb/src/wallets/in-app/web/lib/auth/oauth.ts

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L47 - L48 were not covered by tests

export const loginWithOauth = async (options: {
authOption: OAuthOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@
});
}

authenticateWithRedirect(
async authenticateWithRedirect(
strategy: SocialAuthOption,
mode?: "redirect" | "popup" | "window",
redirectUrl?: string,
): void {
loginWithOauthRedirect({
): Promise<void> {
return loginWithOauthRedirect({

Check warning on line 268 in packages/thirdweb/src/wallets/in-app/web/lib/web-connector.ts

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L267 - L268 were not covered by tests
authOption: strategy,
client: this.client,
ecosystem: this.ecosystem,
Expand Down
Loading