i am trying to set a cookie if a person enters the correct key (1234) but when they type in the correct key it spits out an error
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
idk what to do i tried to redirect before setting the cookie and even just logging after the redirect but the error doesn't go away!
heres my code: key is defined just not in this part
app.get("/", function(req,res) {
if (req.cookies.userSecret == key) {
res.sendFile(__dirname + "/index.html");
} else {
res.sendFile(__dirname + "/login.html")
io.on("connection", function(socket) {
socket.on("login", function(data){
if (data == key) {
res.redirect("/1799fd8e-78aa-4bc0-9692-011a81c07248")
return false;
} else {
io.emit("log", "Wrong key! try again")
return false;
}
})
})
}
});
app.get("/1799fd8e-78aa-4bc0-9692-011a81c07248", function(req,res) {
console.log(key)
res.sendFile(__dirname + "/index.html")
})