react-use-googlelogin
react-use-googlelogin copied to clipboard
refreshUser function doesn't update googleUser
Hi,
I basically copied code from this example: https://github.com/asyarb/react-use-googlelogin/blob/34f5b437a36d694859e113a4305b37a76f86bd91/examples/ssr-nextjs/src/components/GoogleAuthProvider.tsx#L93
const fetchWithRefresh: ContextValue['fetchWithRefresh'] = async (
input,
init
) => {
let tokenId = googleUser.tokenId
const shouldRefreshToken = googleUser.expiresAt - 300 * 1000 - Date.now() <= 0
if (shouldRefreshToken) {
const tokenObj = await refreshUser()
tokenId = googleUser.tokenId
}
return fetch(input, {
...init,
headers: {
...init?.headers,
Authorization: `Bearer ${tokenId}`,
},
})
}
refreshUser()
never refreshses expiresAt value so after an hour when first achieved token expired with each fetch app is going into this if if (shouldRefreshToken)
it seems that for some reason setState
is not working (it is called but old value of googleUser is available in fetchWithRefresh)...
https://github.com/asyarb/react-use-googlelogin/blob/093862e99c3a9b9372a33516ebe6e59cc682785d/src/index.tsx#L222-L242