Skip to content

Commit 8618bde

Browse files
committed
Modify api that fetches user by id
1 parent 9ce038a commit 8618bde

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

backend/user-service/routes/user-routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ router.patch(
2727

2828
router.post("/", createUser);
2929

30-
router.get("/:id", verifyAccessToken, getUser);
30+
router.get("/:id", getUser);
3131

3232
router.patch("/:id", verifyAccessToken, verifyIsOwnerOrAdmin, updateUser);
3333

frontend/src/components/ProfileSection/index.tsx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Avatar, Box, Button, Stack, Typography } from "@mui/material";
1+
import { Avatar, Box, Button, Divider, Stack, Typography } from "@mui/material";
2+
import React from "react";
23

34
type ProfileSectionProps = {
45
firstName: string;
@@ -15,11 +16,17 @@ const ProfileSection: React.FC<ProfileSectionProps> = (props) => {
1516
<Box>
1617
<Box sx={{ display: "flex", flexDirection: "column" }}>
1718
<Box
18-
sx={{ display: "flex", flexDirection: "row", alignItems: "center" }}
19+
sx={(theme) => ({
20+
display: "flex",
21+
flexDirection: "row",
22+
alignItems: "center",
23+
marginTop: theme.spacing(2),
24+
marginBottom: theme.spacing(2),
25+
})}
1926
>
2027
<Avatar sx={{ width: 56, height: 56 }} />
2128
<Box sx={(theme) => ({ marginLeft: theme.spacing(2) })}>
22-
<Typography fontSize={"h5.fontSize"}>
29+
<Typography fontSize={"h6.fontSize"}>
2330
{firstName} {lastName}
2431
</Typography>
2532
<Typography>@{username}</Typography>
@@ -35,18 +42,21 @@ const ProfileSection: React.FC<ProfileSectionProps> = (props) => {
3542
</Typography>
3643
</Box>
3744
{isCurrentUser && (
38-
<Stack
39-
spacing={2}
40-
sx={(theme) => ({
41-
marginTop: theme.spacing(4),
42-
marginBottom: theme.spacing(4),
43-
})}
44-
>
45-
<Button variant="contained">Edit profile</Button>
46-
<Button variant="contained" color="secondary">
47-
Edit password
48-
</Button>
49-
</Stack>
45+
<>
46+
<Divider />
47+
<Stack
48+
spacing={2}
49+
sx={(theme) => ({
50+
marginTop: theme.spacing(4),
51+
marginBottom: theme.spacing(4),
52+
})}
53+
>
54+
<Button variant="contained">Edit profile</Button>
55+
<Button variant="contained" color="secondary">
56+
Edit password
57+
</Button>
58+
</Stack>
59+
</>
5060
)}
5161
</Box>
5262
);

frontend/src/pages/Profile/index.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type UserProfile = {
1616
isAdmin: boolean;
1717
biography?: string;
1818
profilePictureUrl?: string;
19-
createdAt: Date;
19+
createdAt: string;
2020
};
2121

2222
const ProfilePage: React.FC = () => {
@@ -31,15 +31,9 @@ const ProfilePage: React.FC = () => {
3131
const { user } = auth;
3232

3333
useEffect(() => {
34-
// temp user token obtained from the backend to test cors
35-
const accessToken =
36-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY2ZWU2MDI1MTQzOWQ1YWRhNTNhOGIyMiIsImlhdCI6MTcyNzA4MDMzOSwiZXhwIjoxNzI3Njg1MTM5fQ.rofXQgtvcGuEkucv78MTQgqrP0XtPdQ-XPISiW9V_JM";
3734
userClient
38-
.get(`/users/${userId}`, {
39-
headers: { Authorization: `Bearer ${accessToken}` },
40-
})
35+
.get(`/users/${userId}`)
4136
.then((res) => {
42-
console.log(res.data.data);
4337
setUserProfile(res.data.data);
4438
})
4539
.catch(() => setUserProfile(null));

0 commit comments

Comments
 (0)