I’m using the DID token to authenticate/authorize in my backend. This means I need to pass the DID tokens to my backends in every request from my frontend.
The approach I currently use for getting the DID token, is by using the
getIdToken() before every request to the backend is making things very slow.
My rationale for using
getIdToken() before every backend request, was that this would ensure I always got a valid token. I could always cache the token in my app and reuse it, but that would also require some client-side logic for determining whether the cached key is still usable, or if a new one has to be fetched. I’d prefer the SDK to be responsible for this logic.
What is the recommended approach here, to avoid doing this expensive function call slowing down my app?
const t1 = performance.now(); const token = await m.user.getIdToken(); const t2 = performance.now(); console.log("Call to getToken took " + (t2 - t1) + " ms.");