Problem: Once the user has successfully logged in to the app, once in a while (no definite pattern has been identified as to when this happens), ParseUser.getCurrentUser() becomes null even though logout is not called.
Details: We are using Parse SDK on Android to let user log in. This is how we initialize Parse on Application onCreate:
Parse.Configuration.Builder parseConfiguration = new Parse.Configuration.Builder(this)
.applicationId(getString(R.string.parse_app_id))
.clientKey(getString(R.string.parse_client_key))
.server(getString(R.string.parse_server_url))
.enableLocalDataStore();
Parse.initialize(parseConfiguration.build());
In the same method, we also fetch latest info for the user:
if (ParseUser.getCurrentUser() != null) {
ParseUser.getCurrentUser().fetchInBackground();
}
Then in our main activity, if the currentUser is null, we show login screen as follows:
if ( ParseUser.getCurrentUser() == null) {
Intent intent = new Intent(this, LoginActivity.class);
startActivityForResult(intent, LOGIN_REQUEST);
}
In LoginActivity, we get Facebook & Google auth tokens directly (without using Parse SDK). Once we get the facebook/google access token, we then call
Task<ParseUser> parseUserTask = ParseUser.logInWithInBackground("facebook", authData);
Once this task is completed successfully, we let user sign in and use the app. The whole flow works great.
However, once in a while (randomly), user is shown login screen. In our app, we do not call logout or invoke the login screen workflow anywhere. Can someone please suggest what could be the possible cause for this?
If its of any help, we are hosting our server on AWS and initialize it as follows:
var api = new ParseServer({
databaseURI: databaseUri
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID,
masterKey: process.env.MASTER_KEY,
serverURL: process.env.SERVER_URL,
push: {
android: {
senderId: process.env.GOOGLE_GCM_SENDER_ID,
apiKey: process.env.GOOGLE_GCM_API_KEY
}
},
filesAdapter: new S3Adapter(
process.env.S3_AWS_ACCESS_KEY_ID,
process.env.S3_AWS_SECRET_ACCESS_KEY,
process.env.S3_BUCKET_NAME,
{
directAccess: true,
bucketPrefix: process.env.S3_BUCKET_NAME
}
)
});
Thanks, Jaikishan