Refresh access token based on the tenant selected by user on application

Ready to post? :mag: First, try searching for your answer.

I have an app registered and have custom action registered where I add 2 fields from the metadata as custom claims.

On the application (nextjs), I have a user who can be a part of multiple tenants (on my app) and have different roles and permissions in each of them.

I want to provide my user a feature where the user can select a tenant and I get the token with the selected tenant_id as custom claim. The token will be generated every-time the user updates the tenant.

I tried with updating session object and regenerate the token but it only updates the user object in the session.

I checked getAccessTokenSilently but it is outdated.

Is updating the user profile with the current-tenant and refreshing the token the only option ?

Can you please help how I can achieve it ?