File tree Expand file tree Collapse file tree 7 files changed +58
-17
lines changed
app/connect/in-app-wallet
packages/thirdweb/src/wallets/in-app Expand file tree Collapse file tree 7 files changed +58
-17
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " thirdweb " : patch
3
+ ---
4
+
5
+ Prevent popup opening when logging in with auth mode: "redirect"
Original file line number Diff line number Diff line change @@ -80,15 +80,13 @@ function AnyAuth() {
80
80
limits on customizations and auth methods.
81
81
</ p >
82
82
< CodeExample
83
- preview = {
84
- < div className = "w-1/2" >
85
- < CustomLoginForm />
86
- </ div >
87
- }
83
+ preview = { < CustomLoginForm /> }
88
84
code = { `import { useState } from "react";
89
85
import { useConnect } from "thirdweb/react";
90
86
import { inAppWallet, preAuthenticate } from "thirdweb/wallets/in-app";
91
87
88
+ const wallet = inAppWallet();
89
+
92
90
export function CustomLoginUi() {
93
91
const { connect, isConnecting, error } = useConnect();
94
92
@@ -101,10 +99,9 @@ export function CustomLoginUi() {
101
99
});
102
100
};
103
101
104
- const handleLogin = async (email: string, verificationCode: string) => {
102
+ const loginWithEmail = async (email: string, verificationCode: string) => {
105
103
// verify email with verificationCode and connect
106
104
connect(async () => {
107
- const wallet = inAppWallet();
108
105
await wallet.connect({
109
106
client,
110
107
strategy: "email",
@@ -114,6 +111,17 @@ export function CustomLoginUi() {
114
111
return wallet;
115
112
});
116
113
};
114
+
115
+ const loginWithGoogle = async () => {
116
+ // connect with google
117
+ connect(async () => {
118
+ await wallet.connect({
119
+ client,
120
+ strategy: "google",
121
+ });
122
+ return wallet;
123
+ });
124
+ };
117
125
}
118
126
` }
119
127
lang = "tsx"
Original file line number Diff line number Diff line change @@ -27,9 +27,26 @@ export function CustomLoginForm() {
27
27
const wallet = inAppWallet ( ) ;
28
28
await wallet . connect ( {
29
29
strategy : "email" ,
30
- client : THIRDWEB_CLIENT ,
31
30
email,
32
31
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
+ options : [ "google" ] ,
43
+ mode : "redirect" ,
44
+ redirectUrl : `${ window . location . origin } /connect/in-app-wallet` ,
45
+ } ,
46
+ } ) ;
47
+ await wallet . connect ( {
48
+ strategy : "google" ,
49
+ client : THIRDWEB_CLIENT ,
33
50
} ) ;
34
51
return wallet ;
35
52
} ) ;
@@ -41,7 +58,7 @@ export function CustomLoginForm() {
41
58
42
59
if ( screen === "login" ) {
43
60
return (
44
- < div className = "flex flex-col space-y-2 " >
61
+ < div className = "flex w-full flex-col space-y-4 " >
45
62
< label htmlFor = "email" className = "font-medium text-sm" >
46
63
Email Address
47
64
</ label >
@@ -62,6 +79,14 @@ export function CustomLoginForm() {
62
79
>
63
80
{ isConnecting ? "Submitting..." : "Submit" }
64
81
</ button >
82
+ < p className = "text-center text-sm text-white" > Or</ p >
83
+ < button
84
+ type = "button"
85
+ onClick = { loginWithGoogle }
86
+ className = "rounded-lg bg-blue-500 px-4 py-2 text-white transition-colors enabled:hover:bg-blue-600"
87
+ >
88
+ Login with Google
89
+ </ button >
65
90
{ error && < p className = "max-w-[300px] text-red-500" > { error . message } </ p > }
66
91
</ div >
67
92
) ;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export interface InAppConnector {
21
21
strategy : SocialAuthOption ,
22
22
mode ?: "redirect" | "popup" | "window" ,
23
23
redirectUrl ?: string ,
24
- ) : void ;
24
+ ) : Promise < void > ;
25
25
// Login takes an auth token and connects a user with it
26
26
loginWithAuthToken ?(
27
27
authResult : AuthStoredTokenWithCookieReturnType ,
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ export async function connectInAppWallet(
46
46
) {
47
47
const strategy = options . strategy ;
48
48
if ( socialAuthOptions . includes ( strategy as SocialAuthOption ) ) {
49
- connector . authenticateWithRedirect (
49
+ await connector . authenticateWithRedirect (
50
50
strategy as SocialAuthOption ,
51
51
createOptions ?. auth ?. mode ,
52
52
createOptions ?. auth ?. redirectUrl ,
Original file line number Diff line number Diff line change @@ -26,13 +26,13 @@ const closeWindow = ({
26
26
}
27
27
} ;
28
28
29
- export const loginWithOauthRedirect = ( options : {
29
+ export async function loginWithOauthRedirect ( options : {
30
30
authOption : OAuthOption ;
31
31
client : ThirdwebClient ;
32
32
ecosystem ?: Ecosystem ;
33
33
redirectUrl ?: string ;
34
34
mode ?: "redirect" | "popup" | "window" ;
35
- } ) : void = > {
35
+ } ) : Promise < void > {
36
36
const loginUrl = getLoginUrl ( {
37
37
...options ,
38
38
mode : options . mode || "redirect" ,
@@ -42,7 +42,10 @@ export const loginWithOauthRedirect = (options: {
42
42
} else {
43
43
window . open ( loginUrl ) ;
44
44
}
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
+ }
46
49
47
50
export const loginWithOauth = async ( options : {
48
51
authOption : OAuthOption ;
Original file line number Diff line number Diff line change @@ -260,12 +260,12 @@ export class InAppWebConnector implements InAppConnector {
260
260
} ) ;
261
261
}
262
262
263
- authenticateWithRedirect (
263
+ async authenticateWithRedirect (
264
264
strategy : SocialAuthOption ,
265
265
mode ?: "redirect" | "popup" | "window" ,
266
266
redirectUrl ?: string ,
267
- ) : void {
268
- loginWithOauthRedirect ( {
267
+ ) : Promise < void > {
268
+ return loginWithOauthRedirect ( {
269
269
authOption : strategy ,
270
270
client : this . client ,
271
271
ecosystem : this . ecosystem ,
You can’t perform that action at this time.
0 commit comments