해결했는데 이런식의 방법도 괜찮은지 한번 봐주시겠어요 !!?
server.js
app.get('/', async function (req, res) {
res.render('index.ejs');
});
app.post('/', async (req, res) => {
if (req.user) {
const user = await User.findById(req.user).select('-password');
return res.json({ success: true, user });
} else {
return res.json({ success: false });
}
});
header.js
$.post('/').then((data) => {
if (!data.success) {
. . .
} else {
.. . .
}
저는 then을 사용했어요!