Returns the session, refreshing it if necessary.
The session returned can be null if the session is not detected which can happen in the event a user is not signed-in or has logged out.
IMPORTANT: This method loads values directly from the storage attached to the client. If that storage is based on request cookies for example, the values in it may not be authentic and therefore it's strongly advised against using this method and its results in such circumstances. A warning will be emitted if this is detected. Use #getUser() instead.
getClaims()
or getUser()
instead.startAutoRefresh()
in your environment (React Native, etc.) this function always returns a valid access token without refreshing the session itself, as this is done in the background. This function returns very fast.getClaims()
or your own JWT verification library to securely establish the user's identity and access. You can also use getUser()
to fetch the user object directly from the Auth server for this purpose.lock
property, if necessary, to make sure there are no race conditions while the session is being refreshed.const { data, error } = await supabase.auth.getSession()