Repository URL to install this package:
|
Version:
0.0.1 ▾
|
const fetch = require('fetch-everywhere');
const { getUniqueEmail } = require('./gmail-authorize');
const { CONFIG_EMAIL_KEY, CONFIG_FIRST_NAME_KEY, CONFIG_PASSWORD_KEY } = require('../bin/constants');
// This token allows us to create users in any enviornment (besides production)
// because it is a special value that the backend looks for to bypass the recaptcha validation
const RECAPTCHA_TOKEN = 'DvfVrTQ46kghegE75wmAgHGmdaAYV68CHWf5V7N2R6f4uuAUuLeJ43dv8FrmWRvM';
/**
* Make the POST request to create the new user
* @param {String} target
* @param {String} hash
* @param {Object} config
*/
function requestNewUserAccount(target, hash, config) {
const url = `${target}/api/v2.0/users?recaptchaToken=${RECAPTCHA_TOKEN}`;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Origin: 'https://doodle-test.com',
},
body: JSON.stringify({
name: `${config[CONFIG_FIRST_NAME_KEY]} ${hash}`,
email: getUniqueEmail(hash, config[CONFIG_EMAIL_KEY]),
password: config[CONFIG_PASSWORD_KEY],
locale: 'en',
}),
});
}
module.exports = { requestNewUserAccount };