-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Bug: Client is undefined in getToken function #53
Comments
I encountered the same problem with getUser() |
Hey guys, sorry you're experiencing these issues.
We're in the process of cleaning up the SDKs, thanks so much for raising the issue - we'll try make it better for you |
The below is a code excerpt from a context provider in my application, await getToken() fails on the first call of the useEffect hook, but this is recalled by other logic in the application until setToken() is called with a valid token from getToken()
Thanks |
|
Thanks @pwaltron and @simonszalai - we're going to try and recreate the issue and solve it for you ASAP :) |
Hey @pwaltron and @simonszalai, thank you for your patience and for raising the issue. I've put in a fix to 3.0.29-beta.2 A couple things we will need to handle on our side and then we can get it done as a proper release, but for now hopefully this works for you :) |
Should be fixed as a part of the release 4.0.2 |
@peterphanouvong Thank you for the fix!
The getToken function can be undefined. Currently I am using this function to call my API with the Kinde token:
On the first render, kindeToken is undefined, because the function itself is undefined. I understand that getting the token is an async op and somehow it needs to be awaited, but I'm sure there must be a better solution than this one. Could you help me out? Thank you! |
Hey @simonszalai, the |
Thank you, that makes sense. I came up with this hook that seems to work reasonably well, posting it here in case someone else encounters the same issue:
NOTE: using a ref because otherwise isLoading would get stuck in a closure and never change to |
Prerequisites
Describe the issue
We have noticed, usually after a refresh of our application, an error being logged to the console from the SDK;
TypeError: Cannot read properties of undefined (reading 'getToken')
at KindeProvider.tsx:176:1
Is appears that
client
is undefined when we call the getToken function. To get around this we are using getToken within a useEffect hook essentially until we get a returned value. This issue is compounded by #45 as the promise is rejected with an undefined error due to being console logged in the sdk directly.Additionally, we have noticed that the getToken function is declared in kinde-auth-pkce-js/index as having 0 arguments however one argument is being passed in at KindeProvider.tsx:176. It doesn't look like this causes the above issue, but it was a warning from our IDE
Library URL
https://github.com/kinde-oss/kinde-auth-react
Library version
4.0.1
Operating system(s)
macOS
Operating system version(s)
Sonoma 14.0
Further environment details
No response
Reproducible test case URL
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: