Closed RobinJayaswal closed 7 years ago
Okay this explains the odd behavior I was having with the messenger bot. It seems to make me re-login every time I use it. I just get back "cannot complete action right now". It must be sending requests with an expired token.
@gurpreetatwal refactored this to make it more readable. I thought Date.now()
was divided because it returned milliseconds instead of seconds.
I think the problem is that when created_at
is set: https://github.com/smartcar/node-sdk/blob/5cc1e72067292a539a5fa43d294869b01593b6f8/lib/util.js#L19 it is in milliseconds, then when when expires_in
is added it is in seconds.
I think if we set it in properly in seconds in util.js. Or convert everything to milliseconds that should also work:
return Date.now() > access.created_at + (access.expires_in * 1000);
Whoops, that was my bad. I had assumed that created_at
was in seconds being that it is underscore cased like expires_in
.
Should we standardize on ms or seconds?
I'd say if we go with ms
we should camelcase the property so it appears different from the standard oatuh properties
I say we can go seconds, as milliseconds don't really matter here if the expires_in
is in seconds anyways.
Or another option is to set an expiration
property instead of created_at
and also remove the expires_in
. Then all we need to store is access_token
, refresh_token
, and expiration
. And there's no additions that need to be done at compare time.
Use ISO string for expiration
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
Just updated to latest version of SDK, and am running into the following issue.
Here is my code
This prints:
The Unix timestamps are 3 days apart, so it should print Expired. Instead the code continues and I get the following error as soon as I try to use the access token:
I see in line 103 of
index.js
that the check for expiration is this:Is there a reason Date.now() is divided by 1000?