mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Revert "fix(studio): delegate check for expired token to gotrue" (#41268)
Revert "fix(studio): delegate check for expired token to gotrue (#41010)"
This reverts commit 730decf561.
This commit is contained in:
1 parent
91025ec817
commit
16cdd025b7
1 file changed
+16
-10
+16
-10
@@ -159,21 +159,27 @@ gotrueClient.onAuthStateChange((event, session) => {
|
||||
})
|
||||
|
||||
/**
|
||||
* Gets a current access token.
|
||||
*
|
||||
* Calls getSession, which will refresh the token if needed.
|
||||
* Grabs the currently available access token, or calls getSession.
|
||||
*/
|
||||
export async function getAccessToken() {
|
||||
// ignore if server-side
|
||||
if (typeof window === 'undefined') return undefined
|
||||
|
||||
const {
|
||||
data: { session },
|
||||
error,
|
||||
} = await gotrueClient.getSession()
|
||||
if (error) {
|
||||
throw error
|
||||
const aboutToExpire = currentSession?.expires_at
|
||||
? currentSession.expires_at - Math.ceil(Date.now() / 1000) < 30
|
||||
: false
|
||||
|
||||
if (!currentSession || aboutToExpire) {
|
||||
const {
|
||||
data: { session },
|
||||
error,
|
||||
} = await gotrueClient.getSession()
|
||||
if (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
return session?.access_token
|
||||
}
|
||||
|
||||
return session?.access_token
|
||||
return currentSession.access_token
|
||||
}
|
||||
Reference in new issue
Block a user