Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSRF token with express 4 #2

Open
picsoung opened this issue Jul 24, 2014 · 1 comment
Open

CSRF token with express 4 #2

picsoung opened this issue Jul 24, 2014 · 1 comment

Comments

@picsoung
Copy link

I faced a TypeError: Cannot read property 'csrf_tokens' of undefined error when I followed your tutorial. From my understanding it's coming from the latest version of expresse that does not include those middleware by default.

My suggested workaround

npm install csurf cookie-parser express-session

Add:

var csrf = require('csurf');
var cookieParser = require('cookie-parser');
var session = require('express-session')

app.use(cookieParser());
app.use(session({secret: 'keyboard cat'}))

app.use(csrf());
app.use(function(req, res, next) {
  res.cookie('XSRF-TOKEN', req.csrfToken());
  next();
});

and it should be fine 😄

@owenchen
Copy link

owenchen commented Nov 7, 2014

I got the same problem.
It works picsoung. big thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants