Reputation: 626
I have got a .net backend Azure Mobile Service. I have been trying to getting current user information from Android client. I am using the following code
private void authenticate() {
LoginRequest login = new LoginRequest();
login.setUsername(txtUsername.getText().toString());
login.setPassword(txtPassword.getText().toString());
ServiceConstant.mClient.invokeApi("CustomLogin", login, LoginRequest.class,
new ApiOperationCallback<LoginRequest>() {
@Override
public void onCompleted(LoginRequest result,
Exception exception, ServiceFilterResponse response) {
if (exception == null) {
try
{
if (chkRemember.isChecked())
{
cacheUserToken(ServiceConstant.mClient.getCurrentUser());
Toast.makeText(getApplicationContext(),"cache success",Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
Log.e(TAG, "cache fail");
Toast.makeText(getApplicationContext(),
"cache fail",
Toast.LENGTH_SHORT).show();
}
Log.i(TAG, "giris basarili " + result);
Intent intent = new Intent(LoginActivity.this, DeviceScanActivity.class);
startActivity(intent);
} else {
Log.e(TAG, "login fail" + exception);
alert("login", "success\n" + exception);
}
}
});
}
When I try to get current user it returns null. What should I do for getting current user information. I am very newbie to Azure Mobile Service and I haven't any idea for resolve this problem.
Upvotes: 0
Views: 146
Reputation: 1620
This custom login code is based on a custom API, so it's result doesn't get stored automatically like when you work with the built-in login functions.
You need to set the mClient's CurrentUser field manually when you get the result from your API.
If you were following this custom auth tutorial, the return type will actually match the client's MobileServiceUser type, and you can set the value . For more detail, see the last section of that tutorial, titled "Sign in using custom authentication from the client."
Upvotes: 1