From 12770a89105d76b954698a1f3580308d4205eab4 Mon Sep 17 00:00:00 2001 From: Andrew Yang Date: Tue, 23 Jul 2024 16:43:57 +1000 Subject: [PATCH] [EXC-25] get user info example (#2002) --- examples/passport/identity/src/app/page.tsx | 7 +++++++ examples/passport/identity/src/context/passport.tsx | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/examples/passport/identity/src/app/page.tsx b/examples/passport/identity/src/app/page.tsx index 81d4dbc9c3..cbc350ae58 100644 --- a/examples/passport/identity/src/app/page.tsx +++ b/examples/passport/identity/src/app/page.tsx @@ -12,6 +12,7 @@ export default function Home() { getIdToken, getAccessToken, getLinkedAddresses, + getUserInfo, } = usePassport(); return ( @@ -66,6 +67,12 @@ export default function Home() { > Get Linked Addresses + ); diff --git a/examples/passport/identity/src/context/passport.tsx b/examples/passport/identity/src/context/passport.tsx index 25ae11177c..8fa024df23 100644 --- a/examples/passport/identity/src/context/passport.tsx +++ b/examples/passport/identity/src/context/passport.tsx @@ -15,6 +15,7 @@ type PassportContextType = { getIdToken?: () => void; getAccessToken?: () => void; getLinkedAddresses?: () => void; + getUserInfo?: () => void; }; const PassportContext = createContext({}); @@ -123,6 +124,14 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => { window.alert("linkedAddresses: " + linkedAddresses); }, [passportInstance]); + const getUserInfo = useCallback(async () => { + if (!passportInstance) return; + // #doc passport-get-user-info + const userProfile = await passportInstance.getUserInfo(); + // #enddoc passport-get-user-info + window.alert("userProfile: " + JSON.stringify(userProfile)); + }, [passportInstance]); + return ( { getIdToken, getAccessToken, getLinkedAddresses, + getUserInfo, }} > {children}