Hey Descopers, Any thoughts on enabling tenant swi...
# ask-a-descoper
j
Hey Descopers, Any thoughts on enabling tenant switching after a user has already logged into the application? Currently, our login flow includes a tenant selection step before authentication, but we’d like to allow users to switch tenants even after they’ve logged in.
a
@Jai Jamba Yes you can add the switch tenant component to your flow after the authentication action occurs. After switching the tenant and after the flow is over the dct claim in the JWT should be set to the selected tenants id
j
we have that already, but what i am asking is - we want to have this feature of switching between the tenants within the application
a
Let me check
j
?
a
@Jai Jamba This should work for you -
To allow your users to switch tenants inside your application you will need to create another flow like this -
j
sure, let me try..will get back if any questions
🙌 1
a
This will check if the user is logged in, then load the user, and then allow the user to switch the tenant (assuming he has multiple tenants assigned) Once the user selects a tenant the DCT claim in the JWT should get updated.
h
@Atharva Joshi Hey Atharva, thanks for sharing this. I’ve implemented the same flow you provided, and tenant switching is working correctly. However, I’d like to understand the behavior of JWTs after switching tenants. What happens to the old JWT — should it be automatically invalidated by Descope, or do I need to manually invalidate it? Based on the flow you provided, I see that it’s not getting invalidated, and I can still use the old JWT. I also have another question regarding logging out a user. Here’s what I’m doing: =============================== const sdk = useDescope(); cookieUtils.removeUserCookie(); await sdk.logout(); window.location.href = "/"; =============================== if I copy the JWT before logging out and then manually inject that same token afterward, the token still works, I can still call APIs and access the app. It seems like the JWT is not being invalidated. Am I doing something wrong during logout, or is this expected behavior?
a
@Harsh Gor let me check this behavior
👍 1
h
@Atharva Joshi any updates?
a
Regarding the JWT after switching tenants - the only thing that changes is the DCT claim which gets updated to the chosen tenant and you're right the JWT does not get automatically revoked by Descope. If you wish to invalidate them, this doc will be very helpful for you.
Still checking the second question
h
thanks for sharing, will have look on it
🙌 1
a
@Harsh Gor Apologies on the delay regarding the second question But AFAIK i think my first response answered both of your questions ? Long story short - JWT are stateless and thats why they cant be revoked. This is by design . I hope the article i shared was helpful for both of your scenarios?
h
@Atharva Joshi yes both issues were resolved, thanks
🙌 1