Problem of authentification between mobile App and Realm

Hi everyone,

I’m a new French student (in fact worker that try take over studies in programming) and I try to program my first mobile application.
I would like to connect this application to MongoDB and firstly use the login function through email/password authentification. Because it doesn’t work, I tried to use the anonymous authentification that doesn’t work too.

This is an Android app programmed by Android Studio in JAVA.

My code which is si:ply (took on Realm web site):

mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View viewMain) {
App ClientApp = new App(new AppConfiguration.Builder(ClientAppId).build());

            Credentials credentials = Credentials.anonymous();
            ClientApp.loginAsync(credentials, result -> {
                if (result.isSuccess()) {
                    Log.v("QUICKSTART", "Successfully authenticated anonymously.");
                    User user = ClientApp.currentUser();
                    // interact with realm using your user object here
                } else {
                    Log.e("QUICKSTART", "Failed to log in. Error: " + result.getError());
                }
            });
        }
    }); 

If I use the degug mode, I can see that this line stop the login function.

            ClientApp.loginAsync(credentials, result -> {

May somebody could help me and explain me what happen wrong ?

Thank you.

Hi Florian! Welcome to the MongoDB Community Forum!

First: have you completed all the prerequisites (listed here) for the quickstart? You’ll need to create a backend Realm app and connect to that app using the App ID you can find in the Realm UI.

If you’ve completed that, make sure that you’ve enabled Anonymous Authentication. You’ll have to register your anonymous user before you can log in with it – here’s an example of registering an email/password user so you can get a sense of how to do that. Registering an anonymous user should work the same, but with app.getAnonymous() instead of app.getEmailPassword().

Once you’ve registered your anonymous user, you should be able to log in with that user. Keep in mind that these methods are asynchronous, so you’ll have to wait for a successful registration callback before you can log in with that anonymous user.

1 Like

Hi Nathan,

Thank you for your answer.

I did the first step as you sent to me.

  • Init
  • add the dependencies
  • create a class in java
  • validate the anonymous and email/password register even if I use the anonymous in a first time.

And I use the same code as you sent


Sorry, because I’m a new user, I can’t add more than one picture (So, the picture can be unclear).
- First top > The init
- Second top > The class
- bottom > The login code

But it doesn’t work. I guess I do something wrong but what ? :sweat_smile: :unamused: