"Network error: NetworkError when attempting to fetch resource."

Viewed 1077

I am using graph.cool api alongside react and apollo. I was building a authentication system using graph.cools default email pass integration. Somehow the login mutation works flawlessly but the register mutation is not working. Note : Both login and register mutation functions are at the same page. Login working register is not.

Register Function :

async register(){
await client.mutate({
mutation: gql`
   mutation createUser($email: String!, $password: String!){
    createUser(
      authProvider : {
        email: { 
          email: $email, 
          password: $password 
          }
      }
  ) {
    id
  }
}
`,

variables: {
  email: this.state.regEmail,
  password: this.state.regPass
},
})
.then(result => { this.props.history.push({
pathname: '/dashboard',
state: { logInfo: [result.data.signinUser.token, 
                result.data.signinUser.user.id] }
});
})
.catch(error => { console.log(error)});
}

Login Function :

async login(){
 await client.mutate({
  mutation: gql`
     mutation signinUser($email: String!, $password: String!){
    signinUser(
      email: { email: $email, password: $password }
    ) {
      token
      user {
        id
        email
        name
        phone
        prescriptions {
          docname
          docid
          details
          med
        }
      }
    }
  }
  `,

  variables: {
    email: this.state.loginEmail,
    password: this.state.loginPass
  },

})
.then(result => { this.props.history.push({
  pathname: '/dashboard',
  state: { logInfo: [result.data.signinUser.token, 
                  result.data.signinUser.user.id] }
});
 })
.catch(error => { alert("Incorrect username or password") });
}

This is the error

1 Answers

Loos like your server does not have CORS configured correctly

Related