Stanislav Kryvytskyi
03/31/2026, 4:15 PMrefresh with refresh token from /impersonate response.
3. After that everything works fine except 2 issues: useUser still returns original user data and even calling me() doesn't fix it (auth/me returns original user) and after page refresh impersonation stop working
I have persistTokens in AuthProvider. Could somebody help ?DevRev
03/31/2026, 4:15 PMrefresh method from the useDescope hook, the useUser still returns the original user data, and the auth/me endpoint does not reflect the impersonated user. Additionally, impersonation stops working after a page refresh.
Steps to Reproduce
1. Call the impersonate endpoint.
2. Use the refresh method from the useDescope hook.
3. Check the output of useUser and auth/me endpoint.
Potential Solutions
• Ensure that the persistTokens option in the AuthProvider is correctly configured to maintain the impersonation state across page refreshes.
• Verify that the impersonation logic correctly updates the user context after the refresh call.
• Consider implementing a state management solution to handle user data updates more effectively after impersonation.
Next Steps
If the above suggestions do not resolve your issue, please provide additional details about your implementation, including any relevant code snippets. This will help the support team assist you more effectively.
Conclusion
Thank you for your patience. A member of the Descope support team will follow up shortly to assist you further.Stanislav Kryvytskyi
03/31/2026, 4:17 PMexport const useImpersonateUser = () => {
const queryClient = useQueryClient();
const navigate = useNavigate();
const { startImpersonation } = useImpersonationStore();
const { refresh } = useDescope();
return useMutation({
mutationFn: async ({ userEmail }: { userEmail: string }) => {
const originalToken = getRefreshToken();
const response = await impersonationApi.impersonate({
user_email: userEmail,
});
return { response, originalToken };
},
onSuccess: async ({ response, originalToken }, { userEmail }) => {
startImpersonation(originalToken, userEmail);
await refresh(response.refresh_jwt);
queryClient.clear();
await navigate({
to: '/stores',
});
},
});
};Nick Rodriguez
03/31/2026, 10:13 PMrefresh().
Issue 1 — useUser not updating: Calling refresh(impersonated_refresh_jwt) exchanges the token for a new session, but the SDK's internal user state (which useUser subscribes to) may not automatically update from the refresh call alone. You'll need to explicitly call <http://sdk.me|sdk.me>() after the refresh to force the SDK to fetch and populate the impersonated user's data. Try updating your onSuccess handler like this:
onSuccess: async ({ response, originalToken }, { userEmail }) => {
startImpersonation(originalToken, userEmail);
await refresh(response.refresh_jwt);
await <http://sdk.me|sdk.me>(); // force user context to update to impersonated user
queryClient.clear();
await navigate({ to: '/stores' });
},
Issue 2 — Impersonation lost on page refresh: With persistTokens: true, the SDK stores the refresh token in localStorage and uses it to re-initialize the session on page load. If refresh(impersonated_jwt) doesn't write the impersonated refresh token into storage (only uses it for the exchange), the original refresh token remains, and the original session is restored on reload.
To confirm this, could you check your browser's localStorage after calling impersonate — specifically, whether the refresh token key (typically DSR) has been updated to reflect the impersonated user?
Depending on what you find there, the fix may be to explicitly store the impersonated refresh token before navigating. Can you confirm the SDK version you're using as well?Stanislav Kryvytskyi
04/01/2026, 8:06 AMme() after refresh, it returns original user data.Stanislav Kryvytskyi
04/01/2026, 8:37 AMgetSessionToken returns impersonated returns correct user (impersonated)Stanislav Kryvytskyi
04/01/2026, 8:42 AM