-
-
Notifications
You must be signed in to change notification settings - Fork 735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ParseUser user.saveEventually() always create new user in database #850
Comments
I would remove the |
@Jawnnypoo If |
Btw, If I use |
Also struggling with this, did you encounter any further issues when creating anonymous users with |
@AlejandroHCruz yes, I still struggle with this issue, the User collection grows very fast compare to Installation collection. For now I switch to use Installation pointer for "relation" instead. |
Gotcha, thanks! |
So, the issue is that the ParseAnonymousUser is actually not getting saved properly, which results in no user being available when the app starts again. So the usual path of creating a new anon user is followed. The solution that worked for me was like below: In my Application file @Override
public void onCreate() {
...
// Enable automatic creation of ParseAnonymousUser
ParseUser.enableAutomaticUser();
// Login the anonymous user so as to create an entry in the Parse's User table
loginAnonUserIfNeeded()
} where void loginAnonUserIfNeeded() {
// If the current user does not have the object id then it is
// an anon user, then go ahead and login the user into parse
if (ParseUser.getCurrentUser() != null
&& ParseUser.getCurrentUser().getObjectId() == null) {
// call to login only creates the anon user but does not persist it
ParseAnonymousUtils.logIn((user, e) -> {
if (e == null) {
// The user returned here is ParseUser object which is now stored in remote Parse
// server. If the login was not successful this will be null. So we check for the
// user object that si returned is not null and login was successful.
if (user != null) {
// After login, save is required so that it persists across app starts
// ⚠️ WARNING: Do not use saveEventually as it is buggy and creates new anon user
// every time app is opened
user.saveInBackground(e1 -> {
if (e1 == null) {
//User was saved successfully
} else {
// Print stacktrace of the error
e1.printStackTrace();
}
});
}
} else {
// Print stacktrace of the error
e.printStackTrace();
}
});
}
} How to test this: Setup OkHttpInterceptor for logging outgoing calls to Parse Server and you can validate that the create user call is made only once. I hope this helps others who bump into this problem in the future 😄 |
Great solution! Please take into account that |
ParseUser was newly created every time I use user.saveEventually(). I checked in the ParseDashboard, the Installation object for my device is unique but the "user" field in Installation table always different every time I completely close the app (back pressed, wipe out recently apps) and reopen it. The User table has new row too.
My code:
I use latest ParseServer and:
implementation "com.parse:parse-android:1.17.3"
The text was updated successfully, but these errors were encountered: