제로초님 강의로 인해 코딩이 더욱 재밌어지고 배우는게 많은거 같아서 감사드립니다.
질문1. 로그인을 할 경우 밑의 login라우터가 실행 되잖아요?
router.post('/login', isNotLoggedIn, (req, res, next) => {
passport.authenticate('local', (err, user, info) => {
if (err) {
console.error(err);
return next(err);
}
if (info) {
return res.status(401).send(info.reason);
}
return req.login(user, async (loginErr) => {
if (loginErr) {
console.error(loginErr);
return next(loginErr);
}
const fullUserWithoutPassword = await User.findOne({
where: { id: user.id },
attributes: {
exclude: ['password']
},
include: [{
model: Post,
attributes: ['id'],
}, {
model: User,
as: 'Followings',
attributes: ['id'],
}, {
model: User,
as: 'Followers',
attributes: ['id'],
}]
})
console.log(":::::::::::::",JSON.stringify(fullUserWithoutPassword),"enddddddddd")
return res.status(200).json(fullUserWithoutPassword);
그런데 이때 서버에러를 일으켜서
if (err) {
console.error(err);
return next(err);
}
이 구문이 실행되면 return next(err)로 인해 여기서 멈추고 밑의 코드로 더 이상 실행되지 않는것인가요?
질문2. postForm에서 짹짹누르면 리듀서와 사가를 거쳐 백엔드에서 routes폴더의 post.js에서 post라우터가 실행되잖아요?
const fullPost = await Post.findOne({
where: { id: post.id },
include: [{
model: Image,
}, {
model: Comment,
include: [{
model: User, // 댓글 작성자
attributes: ['id', 'nickname'],
}],
}, {
model: User, // 게시글 작성자
attributes: ['id', 'nickname'],
}, {
model: User, // 좋아요 누른 사람
as: 'Likers',
attributes: ['id'],
}]
})
res.status(201).json(fullPost);
위의 코드가 실행되면서 디비에서 찾은 정보를 fullpost변수에 담은 후 클라이언트로 보내주잖아요? 그런데 이때 댓글 작성자와 게시글 작성자와 좋아요 누른사람은 왜 가져오는지 모르겠습니다. 왜나하면 짹짹을 누르면 index.js에서
useEffect(() => {
dispatch({
type: LOAD_USER_REQUEST,
});
dispatch({
type: LOAD_POSTS_REQUEST,
});
}, []);
위의 코드가 실행되어서 포스트정보랑 유저정보 다 가져와서 렌더링되지 않나요?...
뭔가 알것 같은데 막혔습니다 ㅜㅜ 왜 fullpost의 데이터를 클라이언트로 보내주는지 설명부탁드립니다 ㅜ
질문3.
const isFollowing = me?.Followings.find((v) => v.id === post.User.id);
me?.
?. 문법에 대한질문 입니다. 강의에서도 설명하셨지만 제가 이해한것이 맞는지 여쭈고 싶습니다.
me에 데이터가 있을경우 me.Following이 되고 me가 없을 경우 그냥 Following 이 되는 것인가요?
이문법은 어떤 용어의 연산자인가요?