the below code is a get request to a route that serves the user a particular page if authenticated, and redirects the user if not. “request.user” refers to some Passport (a node package) object that gets created upon authentication.
app.get("/newpoll", function (request, response){
if (request.user){
response.sendFile(__dirname + '/views/newpoll.html');
} else {
response.redirect("/")
}
})
can an unauthenticated user access the route through a post request?
app.post("/newpoll", function(request, response){
var poll;
request.on('data', function(data) {
poll = JSON.parse(data);
poll["user"] = request.user.twitterId;
console.log("received: " + JSON.stringify(poll))
MongoClient.connect(url, function(err, db){
if (db){
console.log("connected to " + url);
db.collection("polls").insert(poll);
}
if (err) {
console.log("did not connect to " + url)
}
})
})
})