UNPKG

@codemaster138/authy-client

Version:
26 lines 1.05 kB
export default async function createUser(g, { username, email, password}) { return new Promise((resolve, reject) => { if (!g.app) reject('Must define app before using authy'); if (!username) reject('Missing required argument: config.username'); if (!email) reject('Missing required argument: config.email'); if (!password) reject('Missing required argument: config.password'); fetch(`${g.protocol}://${g.host}:${g.port}/create`, { headers: [ ['content-type', 'application/json'] ], method: 'post', body: JSON.stringify({ app: g.app, name: username, email: email, pass: password }) }) .then(res => { if (res.status.toString()[0] === '2') return res.text().then(data => resolve(data)); return res.text().then(data => reject(data)); }).catch(err => { reject(err); }); }); }