"expiresIn" option not working with sequelize object
See original GitHub issueThe token is created but never expires. I am getting the object from a query to a relational db with the sequelize package. Code example:
models.User.findOne({ where: {username: req.body.name} }) //Returns an object user or null
.then(function(user) {
if (user) {
console.log(typeof user); //Logs "object"
// Check if password matches
if (user.password != req.body.pass) {
res.json({ message: 'Authentication failed. Wrong password.' });
} else {
// If user is found and password is right create a token
var token = jwt.sign(
user,
'shhhhh',
{
expiresIn: 60 // expires in 1 minute
}
);
// Shows the token
console.log(token);
}
} else {
console.log("User not found");
}
}).catch(function(error){
whatever...
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:21 (3 by maintainers)
Top Results From Across the Web
jsonwebtoken.sign() fails with expiresIn option set
If I remove options object at all, it works, but without options I need to set. The issue seems to be simple but...
Read more >Building a PostgreSQL API in JavaScript with Express and ...
We've set up two simple models and a working relationship between them, ... Sequelize also gives us a second options hash after the...
Read more >Node.js Express: JWT example | Token Based Authentication ...
Controllers interact with MySQL Database via Sequelize and send HTTP response (token, user information, data based on roles…) to client.
Read more >MySQL Connection With Node.js Using Sequelize and Express
Cons of sequelize: NoSQL doesn't support sequelize as it includes some unexplained issues when additional connections to the database are required. Sequelize ...
Read more >How to Build Web APIs with NestJS, Postgres, and Sequelize
Setting up Sequelize and Postgres Database; Authentication with Passport ... a token and user object, if not, it will throw an exception.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am using a similar method that works for me, except that I only use only the username as token:
What infos does decoding your token give on http://jwt.io/ ?
I’m using a similar way to sign the token and am occurring the same problem at the moment. Everything works fine, however the token doesn’t seem to expire. I’m storing the token in the localstorage of the browser.