Reputation: 13
I am planning to create an simple login page using node js and jwt.
I feel like storing web token in separate table using user id as foreign key is better.
Can anyone provide me some opinion about this ?
Upvotes: 1
Views: 3239
Reputation: 2008
If you are using a relational database (e.g. SQL) I would recommend storing session data (such as a JWT token) in a separate table with a one-to-many relationship so that the user can theoretically have multiple sessions logged in simultaneously.
If you don't want simultaneous sessions, it doesn't really matter, though you may still choose to use a separate table to future-proof your design (in case you want to add that functionality later).
If you are using a non-relational database (e.g. MongoDB) you can either use a separate collection or put your session objects inside an array inside the Users collection.
Upvotes: 6