-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1db4d53
commit 926184b
Showing
1 changed file
with
23 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
import {Accounts} from 'meteor/accounts-base' | ||
import {Meteor} from 'meteor/meteor' | ||
|
||
export default async function (root, { token }, {userId}) { | ||
const user = Meteor.users.findOne({ | ||
_id: userId, | ||
'services.resume.loginTokens.hashedToken' : Accounts._hashLoginToken(token) | ||
export default async function (root, { token }, context) { | ||
let userId = null; | ||
|
||
const user = await Meteor.users.findOne({ | ||
_id: context.userId, | ||
'services.resume.loginTokens.hashedToken': Accounts._hashLoginToken(token), | ||
}, { | ||
fields: { | ||
_id: 1, | ||
'services.resume.loginTokens.$': 1, | ||
}, | ||
}); | ||
|
||
if (user) { | ||
const loginToken = user.services.resume.loginTokens[0]; | ||
const expiresAt = Accounts._tokenExpiration(loginToken.when); | ||
const isExpired = expiresAt < new Date(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
META-DREAMER
Author
Contributor
|
||
|
||
if (!isExpired) { | ||
userId = user._id; | ||
} | ||
} | ||
return { | ||
success: !!user, | ||
userId: user._id || null | ||
success: !!userId, | ||
userId | ||
}; | ||
} |
Just wondering if expiresAt can be compared with new Date(), without being explicitly "casted" as a JavaScript Date object, it may be interesting to test if expiresAt is a valid Date object, if not throwing an error? Good job btw!