-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#18 implement properties.timeout for account().tokens.add(properties) #43
Conversation
@gr2m the hoodie-account-server-api doc lists under api.account().tokens.add() that the token would store the creation date Am I missing something about how the tokens should work? |
you are right, the token methods have been added in a hurry as it looks, there seem rather incomplete We usually start with a README for a new project and then implement it backwards, so it’s possible that we sometimes miss things. I agree that we need the createdAt timestamps in order for timeout to be useful. I would add it to the |
@@ -15,6 +15,9 @@ function addTokenToUserDoc (db, account, token) { | |||
var id = token.id || uuid.v4() | |||
delete token.id | |||
|
|||
var now = new Date(Date.now()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can leave out the Date.now()
, new Date()
should do the same thing.
You can also shorten the two lines to token.createdAt = new Date().toISOString()
if you don’t use the now
variable anywhere else
@@ -13,6 +13,10 @@ function account (setupPromise, state, findAccountOptions) { | |||
return Promise.reject(errors.TOKEN_TYPE_INVALID) | |||
} | |||
|
|||
if (!tokenOptions.hasOwnProperty('timeout')) { | |||
tokenOptions.timeout = 7200 | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m sorry I should have thought about this earlier, but can we add another timestamp expiresAt
instead of adding a timeout
property? It will be simpler to lookup later as we can directly look for that property without any calculation. Or do you see any downside with that approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I agree that would be a more practical approach, as well as more conventional. I'll change it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you’re the best 🙌
This looks all good 👍 thanks! Only thing left is to update the README now, where it still says "TO BE DONE" for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey I’m so sorry, I found another bug right now, you put in the check for sessions.add
, but we also use the token authentication in other places. I think we should put in the check into find-user-doc-by-username-or-id-or-token.js as it’s used in all the places. Could you make that change, please?
@gr2m, no worries, that makes more sense. Long post ahead... I think I've found a bug that came up in email-verification-test.js#L35 when I moved the expiration check to
The test still works because the query would still respond with the userdoc (not sure how that works). Is this by design? This creates a problem because I've moved the expiration check into that snippet:
|
can you push your current state please?
That sounds like a bug, the
|
upstream update
email-verification-test.js failing
…i into 18_timeout
…, email-verification-test.js failing
I've pushed my current state with email-verification-test.js still failing. If the id should be returned with the token, that would solve the problem. |
yes, because it would be the same value as the |
I see. Ok then I will go ahead and add the id to the result of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work 👍👏
@gr2m sure that sounds great! |
closes #18