Skip to content

Instantly share code, notes, and snippets.

@svnlto
Last active July 17, 2017 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svnlto/8ebca37ce7437d722c7e7a5793f2248b to your computer and use it in GitHub Desktop.
Save svnlto/8ebca37ce7437d722c7e7a5793f2248b to your computer and use it in GitHub Desktop.
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