[英]how to get token when sign up using graphql in flutter
hello i am trying to get the token value when user is signing up.您好,我正在尝试在用户注册时获取令牌值。 i am running mutation query for signing up a new user but my problem is i don't know how to get the token when sign up is successful.我正在运行突变查询以注册新用户,但我的问题是注册成功后我不知道如何获取令牌。
this is the api endpoint https://agro-e-commerce.herokuapp.com/graphql and this is my mutation query in graphql playground这是 api 端点https://agro-e-commerce.herokuapp.com/graphql这是我在 graphql 游乐场中的变异查询
mutation{
signUp(data: {
full_name:"",
user_name:"",
email:"",
phone:"",
password:"",
division:"",
region:"",
address:""
}){
token}
}
here is my code in flutter这是我颤动的代码
String query0 = """
mutation run(\$full_name: String!,\$user_name:String!,\$email:String!,
\$phone: String!,\$password: String!,\$division: String!,\$region:String!,\$address: String!){
signUp(data:{
full_name:\$full_name
user_name:\$user_name,
email:\$email,
phone:\$phone,
password:\$password,
division:\$division,
region:\$region,
address:\$address
}){
token
}
}
body: new Mutation(
builder: (RunMutation runMutation, QueryResult result) {
return FloatingActionButton(
child: new Icon(Icons.add),
onPressed: () {
runMutation({
'user_name': 'anikkoll',
'full_name': 'anikk karmokerkll',
'email': 'anikjkoy78749kl@gmail.com',
'phone': '0167605672879',
'password': 'password',
'division': 'barishal',
'region': 'barishal sadar',
'address': 'kawnia'
});
},
);
},
options: MutationOptions(document: query0),
onCompleted: (resultdata) {
print(resultdata);
}
i expected only token but i got this我只期望令牌,但我得到了这个
{signUp: {token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjgzYTQzMzJhLTk2OWQtNDI3Mi05OWY3LTdiOWNjN2ZlNDhkOCIsImVtYWlsIjoiYW5pa2prb3k3bDg3NDlrbEBnbWFpbC5jb20iLCJ1c2VyX25hbWUiOiJhbmlra29vbGwiLCJyb2xlIjoiQ09OU1VNRVIiLCJpbWFnZSI6bnVsbCwiZnVsbF9uYW1lIjoiYW5pa2tsIGthcm1va2Vya2xsIiwicGhvbmUiOiIwMTU3NjA1NjcyODc5IiwiYWRkcmVzcyI6Imthd25pYSIsInJlZ2lvbiI6ImJhcmlzaGFsIHNhZGFyIiwiZGl2aXNpb24iOiJiYXJpc2hhbCIsImlhdCI6MTU2MzE3ODkxOSwiZXhwIjoxNTYzNzgzNzE5fQ.qCpES_c-dtk7nr-EXqTbTWjIdj4OMqB2HBsEwFXDMlc}}
In your query, you are requesting only the token.在您的查询中,您只请求令牌。 In return, you got your token.作为回报,你得到了你的令牌。
This is the token you want now you just have to decode it.这是您现在想要的令牌,您只需对其进行解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.