I'm using the AWSMobileClient to signup a new user. After they successfully sign up I would like to store their unique uuid aka "sub" id in my SQL database.
AWSMobileClient.getInstance().signUp(username, password, attributes, null, new
Callback<SignUpResult>() {
@Override
public void onResult(final SignUpResult signUpResult) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//Successful signing up a new user
//What would I do here?
}
});
}
@Override
public void onError(Exception e) {
Log.e(TAG, "Sign-up error", e);
}
The user successfully signs up, would I make a post request to my database in the callback method? What happens if the user's network fails during midcall or something else happens and the post request doesn't successfully record the user's uuid. What would be the correct way of doing this?
@bobguy1234 Thanks for reaching out. I have submitted a PR https://github.com/aws-amplify/aws-sdk-android/pull/1107 that exposes userSub in the SignUpResult returned in the callback upon successful sign up. I do not have a firm timeline but this should be released in next couple of weeks. Once that is available, you can make post call to database to record usersub in the database. You will have to handle error conditions such as network failure there itself as follows :
AWSMobileClient.getInstance().signUp(username, password, attributes, null, new
Callback<SignUpResult>() {
@Override
public void onResult(final SignUpResult signUpResult) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//Successful signing up a new user
try {
// Make a post request to store signUpResult.getUserSub() to the database
} catch {
// Deal with the failure condition here
}
}
});
}
@Override
public void onError(Exception e) {
Log.e(TAG, "Sign-up error", e);
}
Alternatively, you can use a countdown latch to wait for successful completion and make post request on the calling thread as follows :
CountDownLatch signUpLatch = new CountDownLatch(1);
AWSMobileClient.getInstance().signUp(username, password, attributes, null, new
Callback<SignUpResult>() {
@Override
public void onResult(final SignUpResult signUpResult) {
runOnUiThread(new Runnable() {
@Override
public void run() {
//Successful signing up a new user
signUpLatch.countDown();
}
});
}
@Override
public void onError(Exception e) {
Log.e(TAG, "Sign-up error", e);
}
// Wait for the latch
try{
signUpLatch.await();
} catch {
// error handling
}
/** Snippet for post request to database and corresponding error handling logic */
Hope that helps!
@bobguy1234 PR https://github.com/aws-amplify/aws-sdk-android/pull/1107 has been merged and will be out in the next release. Please feel free to give it a try once it is out and let me know if you have any feedback.
Closing this issue as the code changes to expose userSub through SignUpResult is released.
Most helpful comment
@bobguy1234 Thanks for reaching out. I have submitted a PR https://github.com/aws-amplify/aws-sdk-android/pull/1107 that exposes userSub in the SignUpResult returned in the callback upon successful sign up. I do not have a firm timeline but this should be released in next couple of weeks. Once that is available, you can make post call to database to record usersub in the database. You will have to handle error conditions such as network failure there itself as follows :
Alternatively, you can use a countdown latch to wait for successful completion and make post request on the calling thread as follows :
Hope that helps!