Skip to content

Commit

Permalink
feat: 헤더 User정보 가져오기 / fix: run build 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
rladmswo1715 committed May 20, 2024
1 parent 52fa5cf commit 7317cf8
Show file tree
Hide file tree
Showing 10 changed files with 747 additions and 510 deletions.
8 changes: 6 additions & 2 deletions api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ interface SignUserData {
password: string;
}

export const getSignInProfile = async () => {
export const getSignInProfile = async (userToken: string) => {
let result = null;

try {
const response = await fetch(`${BASE_URL}/api/sample/user`);
const response = await fetch(`${BASE_URL}/api/users`, {
headers: {
Authorization: `Bearer ${userToken}`,
},
});
if (!response.ok) {
throw new Error(`${response.status}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const FolderAddModalContent = () => {
return (
<S.FolderAddContent>
<input type="text" placeholder="내용 입력" />
<Button type="folderAdd_modal">추가하기</Button>
<Button btnType="button" type="folderAdd_modal">
추가하기
</Button>
</S.FolderAddContent>
);
};
Expand Down
6 changes: 5 additions & 1 deletion components/common/modal/modalContent/FolderDeleteContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Button from "@/components/common/Button";

const FolderDeleteContent = () => {
return <Button type="folderDelete_modal">삭제하기</Button>;
return (
<Button btnType="button" type="folderDelete_modal">
삭제하기
</Button>
);
};

export default FolderDeleteContent;
11 changes: 7 additions & 4 deletions components/layout/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ const Header = () => {

const location = useRouter();

const handleLoadUserProfile = async () => {
const userProfile = await getSignInProfile();
const handleLoadUserProfile = async (userToken: string) => {
const userProfile = await getSignInProfile(userToken);

if (userProfile !== null) {
setUser(userProfile);
setUser(userProfile.data[0]);
}
};

useEffect(() => {
handleLoadUserProfile();
const token = localStorage.getItem("userToken");
if (token) handleLoadUserProfile(token);
}, []);

useEffect(() => {
const handleHeaderScroll = () => {
setIsScrolled(window.scrollY !== 0);
};
Expand Down
11 changes: 3 additions & 8 deletions components/layout/header/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ interface IUser {
const userProfile = ({ user }: IUser) => {
if (!user) {
return (
<S.LoginBtn href="/pages/auth/signin.html" className="btn">
<S.LoginBtn href="/signin" className="btn">
로그인
</S.LoginBtn>
);
}
const { email, profileImageSource } = user;
const { email, image_source } = user;

return (
<S.UserProfileWrap>
<Image
src={profileImageSource}
width={50}
height={50}
alt="유저 프로필"
/>
<Image src={image_source} width={50} height={50} alt="유저 프로필" />
<span>{email}</span>
</S.UserProfileWrap>
);
Expand Down
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const nextConfig = {
"testing-library.com",
"static.cdninstagram.com",
"codeit-front.s3.ap-northeast-2.amazonaws.com",
"avatars.githubusercontent.com",
],
},
};
Expand Down
Loading

0 comments on commit 7317cf8

Please sign in to comment.