diff --git a/src/components/Login/AccountDropdown.astro b/src/components/Login/AccountDropdown.astro
index 6b37bbc3a..fa6b14408 100644
--- a/src/components/Login/AccountDropdown.astro
+++ b/src/components/Login/AccountDropdown.astro
@@ -11,14 +11,6 @@
class='absolute right-0 z-10 mt-2 hidden w-48 rounded-md bg-slate-800 py-1 shadow-xl'
>
- -
-
- Your Profile
-
-
-
{
setIsLoading(false);
- setName('');
- setGithub('');
- setLinkedin('');
- setWebsite('');
- setError('');
+ setName(data.name);
+ setEmail(data.email);
+ const { github, linkedin, website } = data.links;
+ setGithub(github);
+ setLinkedin(linkedin);
+ setWebsite(website);
setSuccessMessage('Profile updated successfully');
})
.catch((err) => {
@@ -56,6 +58,50 @@ export default function UpdateProfileForm() {
});
};
+ // Make a request to the backend to fill in the form with the current values
+ useEffect(() => {
+ async function fetchProfile() {
+ // Set the loading state
+ setIsLoading(true);
+
+ // Create headers with the cookie
+ const headers = new Headers();
+ headers.append('Content-Type', 'application/json');
+ headers.append(
+ 'Cookie',
+ `${TOKEN_COOKIE_NAME}=${Cookies.get(TOKEN_COOKIE_NAME)}`
+ );
+
+ try {
+ const res = await fetch('http://localhost:8080/v1-me', {
+ method: 'POST',
+ credentials: 'include',
+ headers,
+ });
+
+ const json = await res.json();
+ if (res.ok) {
+ setName(json.name);
+ setEmail(json.email);
+
+ if (json.links) {
+ const { github, linkedin, website } = json.links;
+ setGithub(github);
+ setLinkedin(linkedin);
+ setWebsite(website);
+ }
+ } else {
+ throw new Error(json.message);
+ }
+ } catch (error: any) {
+ setError(error?.message || 'Something went wrong');
+ }
+ setIsLoading(false);
+ }
+
+ fetchProfile();
+ }, []);
+
return (