getUser() vs getClaims()
Hey guys,
Previously when we were using
getUser(), we would also cache it like:
Is this still relevant when using getClaims()?
Thanks for your help!9 Replies
I think the using
getClaims() makes a request to /auth/v1/.well-known/jwks.json endpoint for your project to get the public key to decrypt so caching probably still is relevant to avoid having to make that requestthank you a lot for the answer @ihm40 ! Do you perhaps also know why
getClaims() does not return a type with email etc? created an issue here too : https://github.com/supabase/auth-js/issues/1128GitHub
Provide TypeScript types for documented JWT claims fields (email, p...
Refactor Request Describe the refactor The getClaims() method returns JwtPayload with type RequiredClaims & { [key: string]: any }, which doesn't provide TypeScript types for common Supabas...
hmm it should be a return value. What does your getClaims currently return? Obviously annonnymise as needed
getClaims still generate a network request but it is usually to the CDN for a number of requests versus all the way to the SB server every time.
Note though the claims only change when the JWT refreshes versus getUser will get the latest user data from auth.users. This is critical for things like user blocked/deleted or any role info set in metadata that must change immediately.
So should we also still cache it or is that not necessary?
Up to you.
Would the Supabase team recommend it to us, I mean. I don't think it is relevant for performance right?
It would be a bit faster. GetClaims still makes a network call with 10’s of msec of latency so really depends on how much you use it.
Yeah. 10 msec is not really worth caching for. But I also wonder if the caching leads to issues