Skip to content

Facebook login error with enablelocaldatastore #350

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

Open
rochadaniel opened this issue Jan 16, 2016 · 6 comments
Open

Facebook login error with enablelocaldatastore #350

rochadaniel opened this issue Jan 16, 2016 · 6 comments

Comments

@rochadaniel
Copy link

Facebook user login doesn't work as expected when I use Parse.enableLocalDatastore, but without Parse.enableLocalDatastore it works perfectly.
I'm currently using com.parse:parse-android:1.11.0 and com.parse:parsefacebookutils-v4-android:1.10.3@aar.
Below is the code i'm trying to execute in production.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Parse.enableLocalDatastore(this);
        if ( BuildConfig.DEBUG ) {
            Parse.initialize(this, "xx", "xx");
        } else {
            Parse.initialize(this, "xx", "xx");
        }
        ParseConfig.getInBackground();
        ParseUser.enableAutomaticUser();
        ParseInstallation.getCurrentInstallation().saveInBackground();
        ParseFacebookUtils.initialize(this);
    }
}
@parse-github-bot
Copy link

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

@wangmengyan95
Copy link
Contributor

Hi @rochadaniel, could you tell us what is expected and actual behaviour? If you get some error or exception, please also include them.

@rochadaniel
Copy link
Author

Hi @wangmengyan95
Thanks for answering. The first time I log in to facebook it works perfectly, but when I log out and try to log back in this error comes up
java.lang.IllegalArgumentException: Cannot save a ParseUser until it has been signed up. Call signUp first.

Here is my logout code:

currentUser.logOut();

and my login code:

public void faceLogin() {

        List<String> readPermissions = Arrays.asList(
                "public_profile",
                "email",
                "user_birthday");
        ParseFacebookUtils.logInWithReadPermissionsInBackground(this, readPermissions, new LogInCallback() {
            @Override
            public void done(final ParseUser currentUser, ParseException err) {
                if (currentUser == null) {
                    Log.e(TAGLOG, "User canceled log in");
                } else {
                    if (err == null) {

                        GraphRequest request = new GraphRequest(
                                AccessToken.getCurrentAccessToken(),
                                "/me",
                                null,
                                HttpMethod.GET,
                                new GraphRequest.Callback() {
                                    public void onCompleted(GraphResponse graphUser) {
                                        if (graphUser != null) {
                                            try {
                                                if (currentUser.isNew()) {

                                                if (graphUser.getJSONObject().has("name")) {
                                                    currentUser.put("name", graphUser.getJSONObject().getString("name"));
                                                }

                                                if (graphUser.getJSONObject().has("id")) {
                                                    currentUser.put("facebookId", graphUser.getJSONObject().getString("id"));
                                                }

                                                /* ... */
                                                /* ParseException here  */
                                                currentUser.saveInBackground(new SaveCallback() {
                                                    @Override
                                                    public void done(ParseException e) {
                                                        if (e == null) {
                                                            ParseInstallation currentInstallation = ParseInstallation.getCurrentInstallation();
                                                            currentInstallation.put("user", currentUser);
                                                            currentInstallation.saveInBackground(new SaveCallback() {
                                                                @Override
                                                                public void done(ParseException e) {
                                                                    /* ... */
                                                                }
                                                            });
                                                        } else {

                                                            Log.e(TAGLOG, "Error: " + e.getMessage());

                                                        }

                                                    }
                                                });

                                            } catch (JSONException exx) {                                                                                          
                                                Log.e(TAGLOG, exx.getMessage());                                             
                                            }
                                        } else {
                                            Log.e(TAGLOG, exx.getMessage());  
                                        }
                                    }
                                });

                        Bundle parameters = new Bundle();
                        parameters.putString("fields", "id,name,email,gender, birthday");
                        request.setParameters(parameters);
                        request.executeAsync();

                    } else {
                        Log.e(TAGLOG, "Error: " + err.getMessage());
                    }

                }
            }
        });
    }

@wangmengyan95 wangmengyan95 self-assigned this Jan 19, 2016
@heliumb
Copy link

heliumb commented Jan 20, 2016

@wangmengyan95 I have the same issue, but even disabling local datastore has not fixed it for me. Initial facebook signup works fine, but after logging out, all subsequent login attempts return a null ParseUser. Same thing happens if you delete the user entirely - rather than signing up again and returning a new ParseUser, it returns null. It's as if something is being saved and not getting cleared by the logout or delete calls. Several people have said disabling localdatastore fixed this for them but it has not for me. I'm currently using com.parse:parse-android:1.12.0 and com.facebook.android:facebook-android-sdk:4.4.0. Only other differences between me and OP are I do not enableautomaticuser and I do not enablelocaldatastore. I'm using the exact code block provided in Parse Android Guide.

ParseFacebookUtils.logInWithReadPermissionsInBackground(this, permissions, new LogInCallback() {
  @Override
  public void done(ParseUser user, ParseException err) {
    if (user == null) {
      Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
    } else if (user.isNew()) {
      Log.d("MyApp", "User signed up and logged in through Facebook!");
    } else {
      Log.d("MyApp", "User logged in through Facebook!");
    }
  }
});

Edit: this seems to show up all over the place online. I've found 4 links on SO and 2 on Google Groups referencing this issue. No definitive answers on any of them. Thanks for any help you can provide!

Edit #2: I just discovered that if I close the app completely and restart it after logging out, then login works. I obviously can't ask the user to close the app and restart it anytime they logout and want to log back in though. To make things even more odd, after the app has been closed that first time, this issue no longer occurs at all. This makes me believe that something is saved when there is a new parseuser signup via facebookutils that is not cleared via the standard logout methods. However, when it is simply a signin rather than a new signup, this is not an issue and a simple logout call is enough to clear everything and login functions properly afterwards. Any idea what could be saved during a new user signup via facebookutils that is not getting cleared by logout and preventing subsequent logins?

SignUp -> Logout -> SignIn (returns null)
Sign Up -> Logout -> Close App/Reopen App -> SignIn (works)
Login -> Logout -> Login (works)

Edit #3: There is clearly something erratic/inconsistent going on with Parse's login/logout because the FBookUtils Login -> Logout -> FBookUtils Login process that worked yesterday no longer works today, and I have not changed a single line of code.

@rochadaniel
Copy link
Author

Hi @heliumb
I had the same problem but solved by removing this line in MyApplication class:

ParseUser.enableAutomaticUser();

and set my Logout to:

AppPreferences appPreferences = new AppPreferences(context);
if (appPreferences.getLogInType().equals("FACEBOOK")) {
    LoginManager.getInstance().logOut();
}
ParseUser.logOut();

I don't know why but it worked

@heliumb
Copy link

heliumb commented Jan 21, 2016

rochadaniel, although your solution didn't work for me, I suspect it's along the right track. It seems like Parse is not sufficiently clearing out the saved facebook data/session info/something when logging out and that is preventing a proper subsequent login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants