DEV Community

Discussion on: How do you handle role/permissions updates with JWT?

Collapse
 
kspeakman profile image
Kasey Speakman

If it is part of the core business that your app is meant to solve, then I understand. (Otherwise, I wouldn't invest too much in solving it until it is proven to be a big enough support burden.) To solve it, seems like you would need to setup a pub/sub system to be notified of changes soon after they happen. From the browser maybe web sockets with long-poll fallbacks. There are numerous pub/sub options for the backend, depending on your needs.

Thread Thread
 
sebastiandg7 profile image
Sebastián Duque G

I get it. But maybe a pub/sub strategy is too much. You could define some specific (not so regular) user events in your app that triggers the authorization data update, like going from a big module to another.

Additionally, reacting to 401 Unauthorized responses could help to deal with this (401 > fetch authorization data).

Thread Thread
 
kspeakman profile image
Kasey Speakman

Additionally, reacting to 401 Unauthorized responses could help to deal with this (401 > fetch authorization data).

For sure. But the back-end will still need a way to be aware of permission changes or else recheck the permission store every request. (If you are still expecting changes to be immediate.)

That’s assuming we are targeting scalable workloads. If the service doesn’t need to scale and it also responsible for making the permission changes, then you might just be able to keep permissions loaded in memory, and update them as changes happen.