File tree Expand file tree Collapse file tree 7 files changed +43
-15
lines changed
app/connect/in-app-wallet
packages/thirdweb/src/wallets/in-app Expand file tree Collapse file tree 7 files changed +43
-15
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,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";
8985import { useConnect } from "thirdweb/react";
9086import { inAppWallet, preAuthenticate } from "thirdweb/wallets/in-app";
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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
4750export const loginWithOauth = async ( options : {
4851 authOption : OAuthOption ;
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments