PropelAuth/react

Auth token not being auto-refreshed and `useAuthInfo` types say it returns `refreshAuthInfo` but `refreshAuthInfo` is undefined

Closed this issue · 8 comments

Hello!

We came across and issue where the auth token wasn't being refreshed so if a user left a page open for ~30 minutes then came back and tried to do something, they'd get an error page. I looked through the @propelauth/react code and found this:

// Periodically refresh the token. The client will only make requests when the authInfo is stale
// Errors are logged and the token will be invalidated separately
useEffect(() => {
    let didCancel = false

    async function refreshToken() {
        try {
            const authInfo = await client.getAuthenticationInfoOrNull()
            if (!didCancel) {
                dispatch({ authInfo })
            }
        } catch (e) {
            console.log("Failed to refresh token", e)
        }
    }

    const interval = setInterval(refreshToken, 60000)
    return () => {
        didCancel = true
        clearInterval(interval)
    }
}, [client])

However, if I keep my network tab open I don't see any requests being made. I then saw in the changelog that there's a function returned from useAuthInfo called refreshAuthInfo, so I tried to write my own hook to refresh the auth token but I'm getting refreshAuthInfo is not a function

Hey @codedbyjordan - for the original issue, do you happen to know which browser the user was using? The library is set up to refresh auth information periodically, and also on key events like switching tabs/refocusing/reconnecting to the internet, so we can look into why that didn't happen here.
If you also want to send us more information about the user, feel free to message us at support@propelauth.com

And for the second issue - which version of @propelauth/react are you currently using?

Hey @codedbyjordan - for the original issue, do you happen to know which browser the user was using? The library is set up to refresh auth information periodically, and also on key events like switching tabs/refocusing/reconnecting to the internet, so we can look into why that didn't happen here. If you also want to send us more information about the user, feel free to message us at support@propelauth.com

And for the second issue - which version of @propelauth/react are you currently using?

Chrome, seems to be working fine in Firefox. We are on 2.0.13. The type definitions are there, the function just doesn't seem to get returned for some reason.

Hey @codedbyjordan - we're having some trouble reproducing this. Would you be able to create us an account so we can try directly in your product? You can use victoria@propelauth.com as the email address for the account.

Hey @codedbyjordan - we're having some trouble reproducing this. Would you be able to create us an account so we can try directly in your product? You can use victoria@propelauth.com as the email address for the account.

I will ask my manager about this.

Regarding the second issue, I think my install was messed up, I blew away my node modules and reinstalled and it's working.

Ah just discovered it only seems to not auto-refresh if I'm logged in, but it works on Chrome if I'm logged out (same with other browsers)

Hey @codedbyjordan - we released a change over the weekend which should address this, mind upgrading and seeing if you still see the same issue?

@andrew-propelauth seems to be working! thanks a ton :)

Definitely! Thanks for confirming