Skip to content

Instantly share code, notes, and snippets.

@nhanco
Created March 26, 2018 15:20
Show Gist options
  • Save nhanco/793a73c67bf75ee8cdba12adc908e09d to your computer and use it in GitHub Desktop.
Save nhanco/793a73c67bf75ee8cdba12adc908e09d to your computer and use it in GitHub Desktop.
csurf
exports.post = (urlPath, postData, callback) => {
axios.post(urlPath, qs.stringify(postData),{
headers: {'X-Requested-With': 'XMLHttpRequest'},
xsrfCookieName:'csrftoken',
xsrfHeaderName:'csrf-token',
data:postData
})
.then(function (response) {
callback(response)
})
.catch(function (error) {
if (error.response) {
callback(error.response.data)
}
});
}
const csrfProtection = csurf({ cookie: true })
const csrfSetHeader = (req, res, next) => {
res.header('csrf-token', req.csrfToken())
res.header('Access-Control-Allow-Origin', '*')
next()
}
server.post("/auth/register",csrfProtection, Auth.register)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment