You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After creating a function to get the currently cached Enode access token and another to refresh it if necessary, we'll want to create a custom HTTPx Auth class to handle the logic for actually determining whether our current token needs to be refreshed. The way we do this is by, after someone makes a request to Enode's API, checking the response HTTP status code. If it's a 401, then we know our access token is no longer valid, and we must request another.
After creating a function to get the currently cached Enode access token and another to refresh it if necessary, we'll want to create a custom HTTPx Auth class to handle the logic for actually determining whether our current token needs to be refreshed. The way we do this is by, after someone makes a request to Enode's API, checking the response HTTP status code. If it's a 401, then we know our access token is no longer valid, and we must request another.
The way this is implemented in HTTPx is by creating a custom Auth class, which we'll pass into our HTTPx clients
auth
argument. See the example under this paragraph in the docs.Here's how this code looks in TypeScript in our own mock API:
https://github.com/openclimatefix/pv-sites-mobile/blob/c5f47fde4c6c2cce6f145f58edbeddbca687be11/lib/enode.ts#L85-L108
The text was updated successfully, but these errors were encountered: