forked from open-sauced/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-user.ts
49 lines (44 loc) · 1.16 KB
/
update-user.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { supabase } from "lib/utils/supabase";
export interface UpdateUserPayload {
name?: string;
email?: string;
bio?: string;
url?: string;
twitter_username?: string;
company?: string;
location?: string;
interests?: string[];
display_local_time?: boolean;
timezone?: string;
github_sponsors_url?: string;
linkedin_url?: string;
discord_url?: string;
}
interface UseUpdateUserProps {
data: UpdateUserPayload;
params?: string;
}
const baseUrl = process.env.NEXT_PUBLIC_API_URL;
const updateUser = async ({ data, params }: UseUpdateUserProps) => {
const sessionResponse = await supabase.auth.getSession();
const sessionToken = sessionResponse?.data.session?.access_token;
try {
const res = await fetch(`${baseUrl}/auth/profile${params ? `/${params}` : ""}`, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${sessionToken}`,
},
method: "PATCH",
body: JSON.stringify({ ...data }),
});
if (res.status === 200) {
return res.json();
} else {
return false;
}
} catch (e) {
return false;
}
};
export { updateUser };