Fix: Refresh access_token if expired #24
Conversation
|
I think a simpler solution would be just to call call |
The problem there is that even though generateTokens is called again async; in the request that needs the tokens (here: ) getToken will still return undefined causing the search to fail. |
I see. I'm not sure holding the outgoing search request before we get tokens is the right approach. Ideally we should always have tokens ready for sync usage if the user is logged in. This could then be easily fixed by just fetching tokens on startup, then we can keep the token pool stocked up over time in the background. I think that's a simpler solution architecture-wise than making the |
What about just trying to refresh the token in these two scenarios:
this should basically mean the pool should always be populated as it will always cause generateTokens to be called on startup if possible, and it will keep the access_token refreshed (which in turn keeps the token pool filled) |
The browser removes the access_token if expired however it's likely we have a refresh_token available to get a new one, so rather than failing and prompting the user to sign in again, we can just try to renew here first.