Here is my table structure:
// users
+----+--------+------------------------+------------------+-------------------------------+
| id | name | email | cookie | /* some other columns */ |
+----+--------+------------------------+------------------+-------------------------------|
| 1 | Jack | [email protected] | ojer0f934mf2... | |
| 2 | Peter | [email protected] | ko4398f43043... | |
| 3 | John | [email protected] | 0243hfd348i4... | |
+----+--------+------------------------+------------------+-------------------------------+
The cookie
column contains a string (the cookie which keeps the user logged in) that is also set into user's devices. As you see, I have just one string (as the cookie) for each user. So all user's devices have an identical cookie.
Most professional programmers tell me:
It would be safer if each device had its own cookie (the cookie of each device should be different than the cookie of other devices, not a constant cookie for all devices)
Well, why? What's wrong with having an identical cookie for all devices? Also as you see I have just one record for the cookie in the database. So if I update that record for a new device, then the previous device(s) will be logged out.
EDIT: Imagine the following scenario (based on different cookies for different devices):
Alice logs in to my site on her computer at home, and stays logged in. Later she logs in on a computer at school as well, and dont sign out when she is done, but she forgets to sign out. She goes home and wants to sign out from her account at school. How can she do that?
The problem with your approach is that you cannot revoke the token from individual devices easily.
. To logout all devicesyou simply delete all server-side tokens for the user
, so to logout one you just delete the corresponding entry for that device.