我正在将graph.cool api与react和apollo一起使用。我正在使用graph.cools默认电子邮件传递集成构建身份验证系统。以某种方式登录突变可以完美地工作,但是寄存器突变不能工作。 注意:登录和注册突变功能都在同一页面上。没有登录工作注册。
注册功能:
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)});
}
登录功能:
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") });
}