Open dani-phillips opened 1 year ago
Hi, there is no onTokenRefresh option for a new fmrest object.
What you could do, is call the login method, every time you run a query...
The more complex design is to refresh the token once it expires, which currently, is not setup.
What you could do, is call the login method, every time you run a query...
The more complex design is to refresh the token once it expires, which currently, is not setup.
Would calling the login method if multiple users are hitting the /customer
endpoint cause any issues with tokens since there is only one instance of fmrest handling all the calls?
If that won't cause any issues then I will just call login every time I run the query, I'm only going to be running that find query and an update query, but this will be open to our customers and there could be a lot of traffic at once for it.
If it would cause issues then I'll just roll my own token refresh system and only login when the token is invalid.
Tokens expire after an hour, so at a minimum you would have to login every hour. If you have a rapid amount of connections within an hour, yes it would be more efficient to only call login after an hour is passed. To handle a lot of traffic, look into queues (bull) or load balancers.
Edit: I guess after analyzing the fmrest.js in /lib there doesn't seem to be any functionality for automatic refreshing of the access token. Was this in a previous version?
I have an app that sets up a new instance of fmrest and provides an
onTokenRefresh
option that is supposed to refresh the token automatically when necessary.So I wanted to test this, so I opened up the web page and loaded a customer's file, and let it sit there for about 30 minutes or so before trying to refresh the page. When I refreshed the page, I received this error in the console:
The app is very simple, here is the code for it:
Am I doing something wrong, or does fmrest not refresh the token, or are my expectations of how it refreshes the token incorrect? I've been using ChatGPT to help me figure it out, but so far I haven't had any luck and ChatGPT says my code is correct and should refresh the token automatically.