Last active
July 17, 2017 06:12
-
-
Save svnlto/8ebca37ce7437d722c7e7a5793f2248b to your computer and use it in GitHub Desktop.
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
const { request } = require('graphql-request'); | |
const chalk = require('chalk'); | |
const ora = require('ora'); | |
const query = ` | |
mutation loginWithEmailPassword($email: String!, $password: String!) { | |
loginWithEmailPassword(input: {email: $email, password: $password}) { | |
idToken | |
} | |
} | |
`; | |
const login = (email, password) => { | |
const spinner = ora('Attempting login...'); | |
spinner.start(); | |
request('url/graphql', query, { | |
email, | |
password, | |
}) | |
.then(({ loginWithEmailPassword }) => { | |
spinner.stop(); | |
console.log(chalk.green(loginWithEmailPassword.idToken)); | |
}) | |
.catch((data) => { | |
spinner.stop(); | |
const { errors } = data.response; | |
errors.forEach((err) => { | |
console.log(chalk.red(err.message)); | |
}); | |
}); | |
}; | |
export default login; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment