Skip to content

Commit

Permalink
[EXC-25] get user info example (#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-yangy authored Jul 23, 2024
1 parent b562f3d commit 12770a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/passport/identity/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function Home() {
getIdToken,
getAccessToken,
getLinkedAddresses,
getUserInfo,
} = usePassport();

return (
Expand Down Expand Up @@ -66,6 +67,12 @@ export default function Home() {
>
Get Linked Addresses
</button>
<button
className="bg-black text-white py-2 px-4 rounded hover:bg-gray-800"
onClick={getUserInfo}
>
Get User Info
</button>
</div>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions examples/passport/identity/src/context/passport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type PassportContextType = {
getIdToken?: () => void;
getAccessToken?: () => void;
getLinkedAddresses?: () => void;
getUserInfo?: () => void;
};

const PassportContext = createContext<PassportContextType>({});
Expand Down Expand Up @@ -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 (
<PassportContext.Provider
value={{
Expand All @@ -136,6 +145,7 @@ export const PassportProvider = ({ children }: { children: ReactNode }) => {
getIdToken,
getAccessToken,
getLinkedAddresses,
getUserInfo,
}}
>
{children}
Expand Down

0 comments on commit 12770a8

Please sign in to comment.