@@ -4,7 +4,7 @@ import { CHAIN_NAMESPACES, IProvider, log, WEB3AUTH_NETWORK, IPlugin } from "@we
44import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider" ;
55import { PasskeysPlugin } from "@web3auth/passkeys-sfa-plugin" ;
66// Import Single Factor Auth SDK for no redirect flow
7- import { ADAPTER_EVENTS , decodeToken , Web3Auth } from "@web3auth/single-factor-auth" ;
7+ import { ADAPTER_EVENTS , decodeToken , UserAuthInfo , Web3Auth } from "@web3auth/single-factor-auth" ;
88import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin" ;
99import { createContext , ReactNode , useCallback , useContext , useEffect , useMemo , useState } from "react" ;
1010
@@ -62,6 +62,7 @@ export interface IPlaygroundContext {
6262 unlinkPasskey : ( id : number ) => void ;
6363 logout : ( ) => void ;
6464 getUserInfo : ( ) => Promise < AuthUserInfo | null > ;
65+ getExternalIdToken : ( ) => Promise < UserAuthInfo | null > ;
6566 showCheckout : ( ) => void ;
6667 showWalletUI : ( ) => void ;
6768 showWalletScanner : ( ) => void ;
@@ -94,6 +95,7 @@ export const PlaygroundContext = createContext<IPlaygroundContext>({
9495 unlinkPasskey : async ( ) => null ,
9596 logout : async ( ) => null ,
9697 getUserInfo : async ( ) => null ,
98+ getExternalIdToken : async ( ) => null ,
9799 showCheckout : async ( ) => null ,
98100 showWalletUI : async ( ) => null ,
99101 showWalletScanner : async ( ) => null ,
@@ -326,6 +328,17 @@ export function Playground({ children }: IPlaygroundProps) {
326328 return null ;
327329 } , [ web3authSFAuth ] ) ;
328330
331+ const getExternalIdToken = useCallback ( async ( ) : Promise < UserAuthInfo | null > => {
332+ if ( web3authSFAuth && web3authSFAuth ?. connected ) {
333+ const data = await web3authSFAuth ?. authenticateUser ( ) ;
334+ setPlaygroundConsoleTitle ( "Id Token" ) ;
335+ setPlaygroundConsoleData ( JSON . stringify ( data , null , 2 ) ) ;
336+ uiConsole ( data ) ;
337+ return data ;
338+ }
339+ return null ;
340+ } , [ web3authSFAuth ] ) ;
341+
329342 const showCheckout = useCallback ( async ( ) => {
330343 if ( ! wsPlugin ) {
331344 uiConsole ( "wallet services plugin not initialized yet" ) ;
@@ -523,6 +536,7 @@ export function Playground({ children }: IPlaygroundProps) {
523536 unlinkPasskey,
524537 logout,
525538 getUserInfo,
539+ getExternalIdToken,
526540 showCheckout,
527541 showWalletUI,
528542 showWalletScanner,
@@ -554,6 +568,7 @@ export function Playground({ children }: IPlaygroundProps) {
554568 unlinkPasskey ,
555569 logout ,
556570 getUserInfo ,
571+ getExternalIdToken ,
557572 showCheckout ,
558573 showWalletUI ,
559574 showWalletScanner ,
0 commit comments