简体   繁体   English

如何将用户限制为只有一个帖子请求

[英]how do I restrict users to only one post request

I'm making a friend finder application.我正在制作一个朋友查找器应用程序。 I want to restrict the users to only one post.我想将用户限制为只有一篇文章。 Here's what I have so far:这是我到目前为止所拥有的:

router.post("/", middleware.isLoggedIn, (req, res) => {
    //get data from form and add to friendfinder array
    var rank = req.body.rank;
    var discord = req.body.discord;
    var valorantid = req.body.valorantid;
    var author  = {
        id: req.user._id,
        username: req.user.username,
    };
    var newFriend = {rank:rank, discord:discord, valorantid:valorantid, author:author};
        //create a new friend finder entry

    Lookinglist.create(newFriend, function(err, newlyCreated){
        if(err){
            console.log(err);
        } else {
            //redirect back to frinedfinder page
            res.redirect("friendfinder");
        }
    });
});  

Do you have a route for /friendfinder ?你有/friendfinder的路线吗? if yes, use this如果是,请使用此

res.redirect("friendfinder");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM