Created
October 26, 2018 16:19
-
-
Save laniltee/aafdb11893f7116db9e845e9461996c1 to your computer and use it in GitHub Desktop.
validation in double submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Submit Form Data | |
app.post('/posts', (req, res) => { | |
const inputTitle = req.body.inputTitle; | |
const inputContent = req.body.inputContent; | |
const inputToken = req.body.inputToken; | |
const cookieToken = req.cookies['csrf-token']; | |
// Checking if Cookie Token matches CSRF Token Submitted | |
if (cookieToken === inputToken) { | |
console.log("Post Content: Valid CSRF Tokens Received !"); | |
res.sendFile('views/form-success.html', {root: __dirname}); | |
} else { | |
console.error("Post Content: No Valid CSRF Tokens Received ! !"); | |
res.sendFile('views/form-error.html', {root: __dirname}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment