loadMYINFO를 만들어서 로그인 한 경우를 계속 호출
router.get("/", async (req, res, next) => {
// GET /user
try {
if (req.user) {
const fullUserWithoutPassword = await User.findOne({
where: { id: req.user.id },
attributes: {
exclude: ["password"],
},
include: [
{
model: Post,
attributes: ["id"],
},
{
model: User,
as: "Followings",
attributes: ["id"],
},
{
model: User,
as: "Followers",
attributes: ["id"],
},
],
});
res.status(200).json(fullUserWithoutPassword);
} else {
res.status(200).json(null);
}
} catch (error) {
console.error(error);
next(error);
}
});
function loadMyInfoAPI() {
return axios.get("/user");
}
function* loadMyInfo(action) {
try {
const data = action.payload;
const result = yield call(loadMyInfoAPI, data);
console.log("result", result);
yield put(loadMyInfoSuccess(result.data));
} catch (error) {
yield put(loadMyInfoFailure(error));
console.log(error);
}
}
const dispatch = useDispatch();
useEffect(() => {
console.log("me", me);
dispatch(loadMyInfoRequest());
}, []); //두 번째 자리를 잊을 경우 무한 반복됨;
//내정보 불러오기 loadMyInfoRequest
loadMyInfoRequest: (state) => {
state.loadMyInfoLoading = true;
state.loadMyInfoError = null;
state.loadMyInfoComplete = false;
},
loadMyInfoSuccess: (state, action) => {
state.loadMyInfoLoading = false;
state.loadMyInfoComplete = true;
state.me = action.payload;
},
loadMyInfoFailure: (state, action) => {
state.loadMyInfoLoading = false;
state.loadMyInfoError = action.error;
},