Open a2kas opened 6 years ago
Are you using any kind of session middleware (such as express-session)?
yes, I am using same code like in the example. here is my code:
app.js
'use strict';
var debug = require('debug');
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var steam = require('steam-login');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
app.use(require('express-session')({ resave: false, saveUninitialized: false, secret: 'a secret' }));
app.use(steam.middleware({
realm: 'http://localhost:3000/',
verify: 'http://localhost:3000/verify',
apiKey: 'my api key'
}
));
app.set('port', 3000);
var server = app.listen(app.get('port'), function () {
debug('Express server listening on port ' + server.address().port);
});
index.js
'use strict';
var express = require('express');
var steam = require('steam-login');
var router = express.Router();
/* GET home page. */
router.get('/', function (req, res) {
res.send(req.user == null ? 'not logged in' : 'hello ' + req.user.username).end();
});
router.get('/authenticate', steam.authenticate(), function (req, res) {
res.redirect('/');
});
router.get('/verify', steam.verify(), function (req, res) {
res.send(req.user).end();
});
router.get('/logout', steam.enforceLogin('/'), function (req, res) {
req.logout();
res.redirect('/');
});
module.exports = router;
Move the lines where you add your routes below the line where you add the session library.
I am getting an error
Cannot set property 'steamUser' of undefined
after signup up, whats can be wrong?