Closed mvayak closed 5 years ago
please try this code
Storefront.CustomerCreateInput customer = new Storefront.CustomerCreateInput(etRegisterEmail.getText().toString(), etRegisterPassword.getText().toString())
.setFirstName(etFirstName.getText().toString())
.setLastName(etLastName.getText().toString())
.setPhone(etMobileNo.getText().toString())
.setAcceptsMarketing(true);
Storefront.MutationQuery query = Storefront.mutation(rootQuery -> rootQuery
.customerCreate(customer, createCustomer -> createCustomer
.customer(customerQuery -> customerQuery
.firstName()
.id()
.email()
.lastName()
.phone()
)
.userErrors(userErrorQuery -> userErrorQuery
.field()
.message()
)
)
);
graphClient.mutateGraph(query).enqueue(new GraphCall.Callback<Storefront.Mutation>() {
@Override
public void onResponse(@NonNull GraphResponse<Storefront.Mutation> response) {
if (!response.data().getCustomerCreate().getUserErrors().isEmpty()) {
for (Storefront.UserError error : response.data().getCustomerCreate().getUserErrors()) {
Log.e("TAG", "error" + error.getMessage());
}
} else {
Storefront.Customer customer = response.data().getCustomerCreate().getCustomer();
Log.e("TAG", "customer " + response.data());
Log.e("TAG", "customer " + customer.getId());
Log.e("TAG", "customer " + customer.getFirstName());
Log.e("TAG", "customer " + customer.getLastName());
Log.e("TAG", "customer " + customer.getPhone());
Log.e("TAG", "customer " + customer.getEmail());
}
}
@Override
public void onFailure(@NonNull GraphError error) {
Log.e("TAG", "customer" + error.getMessage());
}
});
I know about that but my issue is How can I get access token when a new customer is created. Because there is no any parameter for the access token. And SDK new version mention
Return access token for new created customer
Not return any access token for creating new customer. please refer mobile buy sdk android-->Creating a customer.
https://github.com/Shopify/mobile-buy-sdk-android#creating-a-customer-
any query than please ask me.
https://github.com/Shopify/mobile-buy-sdk-android#creating-a-customer-
I know but latest version SDK version provides Return access token for new created customer. Please see it.
@mvayak
I think both url same than not clear your issues.
Mobile buy sdk android clearly define this statement .
Keep in mind that this mutation returns a Storefront.Customer object,
not an access token
After a successful mutation, the customer will still be required to log in using their credentials.
We can get access token while we call registration GraphQL API to see below method. We can call only one API and register the user with access token. we no need to call one API for registration and another for access token.
fun registrationGraphQuery(email: String, password: String, fName: String, lName: String): Storefront.MutationQuery {
return Storefront.mutation { mutation ->
mutation
.customerCreate(inputForRegistration(fName, lName, email, password)) { query ->
query
.customer { customer ->
customer
.id()
.email()
.firstName()
.lastName()
}
.userErrors { userErrors -> userErrors
.field()
.message()
}
}
.customerAccessTokenCreate(inputForLogin(email, password)) { query ->
query
.customerAccessToken { customerAccessToken ->
customerAccessToken
.accessToken()
.expiresAt()
}
.customerUserErrors { userError -> userError.message().field() }
}
}
}
I'm using
gradle and I have tried to get access token using above query But I didn't get.