(주요 로직)
(LoginSlice.jsx)
xport const __kakaoLogin = createAsyncThunk(
"posts/__kakaoLogin",
async (code, thunkAPI) => {
console.log(code)
try {
const res = await axios
.get(`${process.env.REACT_APP_SERVER}/api/member/kakao?code=${code}`);
window.localStorage.setItem("Access_Token", res.data.accessToken);
window.localStorage.setItem("Refresh_Token", res.data.refreshToken);
// 토큰만 로컬에 저장하고 나머지는 스토어에서 관리
window.location.replace("/");
console.log(res)
return thunkAPI.fulfillWithValue(res.data);
} catch (error) {console.log("소셜로그인 에러", error);
window.alert("로그인에 실패하였습니다.");
// 로그인 실패하면 로그인 화면으로 돌려보냄
window.location.replace("/login");
return thunkAPI.rejectWithValue(error);
}
}
);
(SellerPage.jsx)
const SellerPage = () => {
const {myPostList, sellerInfoDto} = useSelector((state) => state.sellerpage)
// 백엔드에서 필요한 정보를 따로 불러온다. 하나는 배열, 하나는 객체
const params = useParams()
const dispatch = useDispatch()
const nickname = params.nickname
useEffect(() => {
dispatch(__getSellerinfo(params.nickname))
}, [nickname])
return (
<div>
<Header/>
<img src={sellerInfoDto.profileImg}/>
<div>판매자 닉네임</div>
{sellerInfoDto.nickname}
<div>판매자 이메일</div>
{sellerInfoDto.email}
<div>물건 리스트
{
myPostList !== undefined && (
<>
{myPostList.map((mypost) => {
return (
<div key={mypost.postId}>
{/* <div>{myPostList.image}</div> */}
<div>{mypost.title}</div>
{/* <div>{myPostList.product}</div> */}
<div>{mypost.userPrice}</div>
</div>
)
})}
</>
)
}