src/lib/solid.ts (view raw)
1import {
2 getSolidDataset,
3 getStringNoLocale,
4 getThingAll,
5 getUrl,
6} from "@inrupt/solid-client";
7import { fetch, getDefaultSession } from "@inrupt/solid-client-authn-browser";
8import { FOAF, VCARD } from "@inrupt/vocab-common-rdf";
9
10export const getProfile = async () => {
11 const session = getDefaultSession();
12 const webId = session.info.webId;
13 if (!webId) return null;
14 const profileDataset = await getSolidDataset(webId, { fetch: fetch });
15 const subjects = getThingAll(profileDataset);
16
17 const findValue = (predicate: string) =>
18 subjects
19 .map(
20 subject =>
21 getStringNoLocale(subject, predicate) || getUrl(subject, predicate)
22 )
23 ?.filter(i => !!i)[0];
24
25 return {
26 name: findValue(FOAF.name),
27 organization: findValue(VCARD.organization_name),
28 image: findValue(VCARD.hasPhoto),
29 webId,
30 };
31};