在我的快递服务器端
module.exports = {
ensureAuthenticated: function(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
res.redirect("/users/login");
}
};
router.get("/dashboard", ensureAuthenticated, (req, res) =>
res.json({ name: req.user.name })
);
使用React前端, 您将如何保护仅授权登录用户的路由?
componentDidMount() {
axios.get("/dashboard")
}