diff --git a/pages/update-profile/index.tsx b/pages/update-profile/index.tsx index 155742b..2238827 100644 --- a/pages/update-profile/index.tsx +++ b/pages/update-profile/index.tsx @@ -2,21 +2,25 @@ import { AdminNav } from "@/components/AdminNav"; import { useForm, SubmitHandler } from "react-hook-form"; import { User } from "@/types/mongo"; import { useGetCurrentUser } from "@/hooks/useGetCurrentUser"; +import { useContext } from "react"; +import { AuthContext } from "@/components/AuthProvider"; -async function updateUser(values: User, id: number) { - const res = await fetch(`${process.env.BACKEND_URL}/users/${id}`, { - method: "patch", +async function updateUser(values: User, idToken: string) { + const res = await fetch(`${process.env.BACKEND_URL}/users/${values._id}`, { + method: "PATCH", headers: { "Content-Type": "application/json", - Authorization: `Bearer ${id}`, + Authorization: `Bearer ${idToken}`, }, body: JSON.stringify(values), }); return await res.json(); } +// TODO: create separate form schema distinct from User export default function UpdateProfile() { const { data } = useGetCurrentUser() + const { idToken } = useContext(AuthContext) const { register, handleSubmit, @@ -30,12 +34,11 @@ export default function UpdateProfile() { bio: data ? data.bio : '' } }); - console.log({ data }) + const onSubmit: SubmitHandler = (formData) => { try { if (data) - // @ts-ignore ts doesn't like mongoose id's - updateUser(formData, data._id) + updateUser({ ...formData, _id: data._id }, idToken) } catch (error) { console.log(error) } diff --git a/types/mongo.ts b/types/mongo.ts index 1277e59..5e2c242 100644 --- a/types/mongo.ts +++ b/types/mongo.ts @@ -41,15 +41,32 @@ export type Pool = { }; export type User = { + _id: string; name: string; profile?: string; bio?: string; socials?: string; - wallet_address: string; + wallets: WalletResolvable[]; email?: string; - session_cookie: string; }; +export type Wallet = { + type: string; +}; + +export type SocialLoginWallet = { + public_key: string; + curve: string; +} & Wallet; + +export type ExternalWallet = { + address: string; +} & Wallet; + +export type WalletResolvable = Partial & + Partial & + Wallet; + type Sponsor = { logo: string; name: string;