I’m building a react application using OSDK, and I would like to display the username of the user OAuth-ed to Foundry. Is it possible to get the username/Name/Surname of the user via OSDK ?
Do you have any code sample ?
I’m building a react application using OSDK, and I would like to display the username of the user OAuth-ed to Foundry. Is it possible to get the username/Name/Surname of the user via OSDK ?
Do you have any code sample ?
YES! you can.
We are releasing docs for this shortly but you can use the following:
Add "@osdk/foundry": "latest",
to your package.json
create a platform client or use the client you already have export const platformClient: PlatformClient = createPlatformClient(FOUNDRY_URL, auth);
Use this code example for inspiration
import { getCurrent, User, profilePicture } from "@osdk/foundry.admin/User";
...
const [user, setUser] = useState<User | undefined>();
const [profilePictureBase64, setProfilePictureBase64] = useState<string | undefined>();
const getProfile = useCallback(async () => {
const result = await getCurrent(platformClient, { preview: true });
setUser(result);
const profilePictureBlob = await profilePicture(platformClient, result.id, {preview:true})
const reader = new FileReader();
reader.onloadend = () => {
const base64data = reader.result as string;
setProfilePictureBase64(base64data);
};
reader.readAsDataURL(profilePictureBlob as Blob);
}, []);
HTH,
Working code:
package.json
"dependencies": {
"@osdk/client": "^2.0.8",
"@osdk/foundry": "^2.6.0",
"@osdk/oauth": "^1.0.0",
client.ts
import { createPlatformClient, PlatformClient } from '@osdk/client'
export const platformClient: PlatformClient = createPlatformClient(url, auth);
Home.tsx
import platformClient from "./client";
import { getCurrent, profilePicture } from "@osdk/foundry.admin/User";
import { User } from "@osdk/foundry.admin";
const [user, setUser] = React.useState<User>();
const getProfile = React.useCallback(async () => {
const result = await getCurrent(platformClient);
setUser(result);
}, []);
...
<div className={css.topLeftSection}>
'Welcome ' + user?.username
</div>
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.