This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add generateVerificationTokenObject fn
Signed-off-by: Eric Dobbertin <[email protected]>
- Loading branch information
Showing
3 changed files
with
34 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Random from "@reactioncommerce/random"; | ||
import ReactionError from "@reactioncommerce/reaction-error"; | ||
|
||
/** | ||
* @summary Creates a verification token object to pass to our | ||
* accounts / users collections for account verification purposes | ||
* @param {Object} [address] email address to create token for | ||
* @param {String} [email] email address to create token for | ||
* @returns {Object} Token object | ||
*/ | ||
export default function generateVerificationTokenObject({ address, email }) { | ||
if (!address && !email) throw new ReactionError("error-occurred", "Address or email required"); | ||
|
||
const tokenObj = { | ||
token: Random.secret(), | ||
when: new Date() | ||
}; | ||
|
||
if (address) { | ||
tokenObj.address = address; | ||
} | ||
|
||
if (email) { | ||
tokenObj.email = email; | ||
} | ||
|
||
return tokenObj; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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