Context
In a flask app, we use a signed cookie (encoded JWT) for user data, however the amount of data has become too large to put in a cookie (specific permissions per item).
Here comes redis, instead of storing the permissions in the JWT and passing it back and forth, we’ll just keep it in redis.
My questions are
- Is there any advantage to having signed session cookies (encoded JWT) AND using redis to store other session information
- Is it better to implement the session logic yourself instead of using something like flask-session
2
Answers
JWT is mostly useful for distibuted applications where the token is generated and used by different applications. So, if all processing happens on a single backend, redis is more flexible.
Implementing your own session logic is probably not a good idea, especially when the session is used for security purposes (authentication).
Even you use
Redis
to store sessions you still need cookies since you will need to query by key and the key will be one the client side, in the cookie.You may just keep the identifier in the cookie but store the rest in redis and you get the details by that identifier.
flask
but, the requirements for thesession
is almost same for the years(get, set, expire, delete) and probably that library supports all the requirements for session related use cases. I would go with the existing one instead of implementing new.