简体   繁体   中英

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

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.

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM