Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
feat: add generateVerificationTokenObject fn
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Dobbertin <[email protected]>
  • Loading branch information
aldeed committed Oct 9, 2019
1 parent a3abed9 commit 0d19adf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/generateVerificationTokenObject.js
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;
}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"sideEffects": false,
"dependencies": {
"@reactioncommerce/logger": "^1.1.2",
"@reactioncommerce/random": "^1.0.1",
"@reactioncommerce/reaction-error": "^1.0.1",
"accounting-js": "^1.1.1",
"graphql-fields": "^2.0.3",
Expand Down

0 comments on commit 0d19adf

Please sign in to comment.