KindeK
Kinde•7mo ago•
8 replies
Mcgeckle

Getting and refreshing access tokens in API client ts file

Hi,

I am working on protecting my API by passing the access token in the headers of the API calls and have a few questions to make sure I'm doing this properly using the React SDK.

I am using openapi-fetch package to call my API and their docs give an example on adding middleware to pass the access token in each request (here). I am using the getRawToken, isAuthenticated, refreshToken utility functions provided in the @kinde-oss/kinde-auth-react/utils import to do this in my API client ts file similar to what is shown in the openapi-fetch docs I linked.

1. In the Kinde docs it states that if you use the getToken function it will automatically refresh the token if it is about to expire. But, when looking at the code I do not see how it would be doing this. Maybe I'm looking in the wrong place or not understanding something correctly (I'm no expert 😅 ). I have not been auto logged out or anything yet, so I assume it is refreshing as stated in the docs, but I just wanted to confirm.
2. Does the getRawToken utility function also auto refresh the token or does it need to be manually refreshed in these cases?

Thanks!
Was this page helpful?