Skip to content

Commit 4eacf3a

Browse files
authored
supabaseContext fixes (#213)
* - * prettier formatting * name
1 parent b7d1384 commit 4eacf3a

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

apps/roam/src/utils/supabaseContext.ts

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,49 +44,44 @@ const fetchOrCreateSpaceId = async (): Promise<number> => {
4444
return space.id;
4545
};
4646

47-
const fetchOrCreatePlatformAccount = async (
48-
{
49-
accountLocalId,
50-
personName,
51-
personEmail
52-
}: {
53-
accountLocalId: string,
54-
personName: string,
55-
personEmail: string | undefined
56-
}): Promise<number> => {
57-
const response = await fetch(
58-
`${base_url}/platform_account`,
59-
{
60-
method: "POST",
61-
headers: {
62-
"Content-Type": "application/json",
63-
},
64-
body: JSON.stringify({
65-
platform: "Roam", account_local_id: accountLocalId, personName
66-
}),
47+
const fetchOrCreatePlatformAccount = async ({
48+
accountLocalId,
49+
personName,
50+
personEmail,
51+
}: {
52+
accountLocalId: string;
53+
personName: string;
54+
personEmail: string | undefined;
55+
}): Promise<number> => {
56+
const response = await fetch(`${base_url}/platform-account`, {
57+
method: "POST",
58+
headers: {
59+
"Content-Type": "application/json",
6760
},
68-
);
61+
body: JSON.stringify({
62+
platform: "Roam",
63+
account_local_id: accountLocalId,
64+
name: personName,
65+
}),
66+
});
6967
if (!response.ok)
7068
throw new Error(
7169
`Platform API failed: \${response.status} \${response.statusText}`,
7270
);
7371
const account = await response.json();
7472
if (personEmail !== undefined) {
75-
const idResponse = await fetch(
76-
`${base_url}/agent-identifier`,
77-
{
78-
method: "POST",
79-
headers: {
80-
"Content-Type": "application/json",
81-
},
82-
body: JSON.stringify({
83-
account_id: account.id,
84-
identifier_type: "email",
85-
value: personEmail,
86-
trusted: false, // Roam tests email
87-
}),
73+
const idResponse = await fetch(`${base_url}/agent-identifier`, {
74+
method: "POST",
75+
headers: {
76+
"Content-Type": "application/json",
8877
},
89-
);
78+
body: JSON.stringify({
79+
account_id: account.id,
80+
identifier_type: "email",
81+
value: personEmail,
82+
trusted: false, // Roam tests email
83+
}),
84+
});
9085
if (!idResponse.ok) {
9186
const error = await idResponse.text();
9287
console.error(`Error setting the email for the account: ${error}`);
@@ -105,7 +100,11 @@ export const getSupabaseContext = async (): Promise<SupabaseContext | null> => {
105100
const accountLocalId = window.roamAlphaAPI.user.uid();
106101
const personEmail = getCurrentUserEmail();
107102
const personName = getCurrentUserDisplayName();
108-
const userId = await fetchOrCreatePlatformAccount({accountLocalId, personName, personEmail});
103+
const userId = await fetchOrCreatePlatformAccount({
104+
accountLocalId,
105+
personName,
106+
personEmail,
107+
});
109108
CONTEXT_CACHE = { platform: "Roam", spaceId, userId };
110109
} catch (error) {
111110
console.error(error);

0 commit comments

Comments
 (0)