Created
March 26, 2018 15:20
-
-
Save nhanco/793a73c67bf75ee8cdba12adc908e09d to your computer and use it in GitHub Desktop.
csurf
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
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) | |
} | |
}); | |
} |
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
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