mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
fix: Fix page logout issue due to refresh-token (#9970)
This commit is contained in:
parent
f47177ecb4
commit
b6d045cebf
|
@ -41,6 +41,7 @@ const useRefreshToken = () => {
|
||||||
return new Error('No access token or refresh token found')
|
return new Error('No access token or refresh token found')
|
||||||
}
|
}
|
||||||
if (localStorage?.getItem('is_refreshing') === '1') {
|
if (localStorage?.getItem('is_refreshing') === '1') {
|
||||||
|
clearTimeout(timer.current)
|
||||||
timer.current = setTimeout(() => {
|
timer.current = setTimeout(() => {
|
||||||
getNewAccessToken()
|
getNewAccessToken()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
@ -61,12 +62,14 @@ const useRefreshToken = () => {
|
||||||
localStorage?.setItem('console_token', access_token)
|
localStorage?.setItem('console_token', access_token)
|
||||||
localStorage?.setItem('refresh_token', refresh_token)
|
localStorage?.setItem('refresh_token', refresh_token)
|
||||||
const newTokenExpireTime = getExpireTime(access_token)
|
const newTokenExpireTime = getExpireTime(access_token)
|
||||||
|
clearTimeout(timer.current)
|
||||||
timer.current = setTimeout(() => {
|
timer.current = setTimeout(() => {
|
||||||
getNewAccessToken()
|
getNewAccessToken()
|
||||||
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const newTokenExpireTime = getExpireTime(currentAccessToken)
|
const newTokenExpireTime = getExpireTime(currentAccessToken)
|
||||||
|
clearTimeout(timer.current)
|
||||||
timer.current = setTimeout(() => {
|
timer.current = setTimeout(() => {
|
||||||
getNewAccessToken()
|
getNewAccessToken()
|
||||||
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
}, newTokenExpireTime - advanceTime.current - getCurrentTimeStamp())
|
||||||
|
@ -74,8 +77,15 @@ const useRefreshToken = () => {
|
||||||
return null
|
return null
|
||||||
}, [getExpireTime, getCurrentTimeStamp, handleError])
|
}, [getExpireTime, getCurrentTimeStamp, handleError])
|
||||||
|
|
||||||
|
const handleVisibilityChange = useCallback(() => {
|
||||||
|
if (document.visibilityState === 'visible')
|
||||||
|
getNewAccessToken()
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
window.addEventListener('visibilitychange', handleVisibilityChange)
|
||||||
return () => {
|
return () => {
|
||||||
|
window.removeEventListener('visibilitychange', handleVisibilityChange)
|
||||||
clearTimeout(timer.current)
|
clearTimeout(timer.current)
|
||||||
localStorage?.removeItem('is_refreshing')
|
localStorage?.removeItem('is_refreshing')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user