Skip to content

Commit 9abd5bd

Browse files
feat: load profile on homepage
1 parent 98b0686 commit 9abd5bd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

frontend/src/pages/MainPage.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
import { useEffect } from "react";
1+
import { useEffect, useState } from "react";
22
import { Header } from "../components/Common/Common";
33
import { OAUTH_LOGIN_URL, useAuthContext } from "../utils/auth";
4+
import { makeRequest } from "../utils/backend";
45

56
function MainPage() {
67
const auth = useAuthContext();
8+
const [subtitle, setSubtitle] = useState<string | null>(null);
9+
10+
const fetchProfile = async () => {
11+
const response = await makeRequest('profile', 'post');
12+
13+
if (response.status == 'success') {
14+
setSubtitle(`Welcome, ${response.data.username}`);
15+
} else {
16+
setSubtitle("Error loading profile (username).");
17+
}
18+
}
719

820
useEffect(() => {
921
if (!auth.isAuthenticated) {
1022
window.location.assign(OAUTH_LOGIN_URL);
23+
} else {
24+
fetchProfile();
1125
}
1226
}, []);
1327

1428
return <>
1529
<Header
1630
title="MetaKGP Maintainers' Dashboard"
31+
subtitle={subtitle ?? undefined}
1732
/>
1833
</>;
1934
}

0 commit comments

Comments
 (0)