Skip to content
Advertisement

FirebaseAuth does not print realtime data in the membership creation step

I have created a membership system in my application. I create record with Firebase Auth and store some information in firebase realtime . However, I saw that 1% of the users did not print their data to firebase realtime during record creation. If users’ data is not written to firebase realtime, my application will crash. I haven’t been able to figure out how to fix this problem for weeks. I would be glad if you help. The table where I store user information: users

Regard.

This my code;

    private void signUp(){

    mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        FirebaseUser user = mAuth.getCurrentUser();
                        writeNewUser(user.getUid(), email);
                 
                    }
                }
            });

}


    private void writeNewUser(String userId, String email) {
    Long duration = Constants.TRIAL_DAY_MILI;
    if (MyApplication.getInstance().getmServer() != null) {
        server serverTime = MyApplication.getInstance().getmServer();
        long unix_seconds = serverTime.Time;
        Date date = new Date(unix_seconds);
        SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
        String java_date = jdf.format(date);
        Integer review = 0;
        boolean subscriptions = false;
        long expiredTime = serverTime.Time + duration;
        User user = new User("User", email,
                1L, messagingToken, deviceId, expiredTime, membership, memberStatus, playerUid, languagename, durum, java_date, subscriptions, review);
        Device device = new Device(messagingToken, deviceId);

        MyApplication.getInstance().setUser(user);
        mDatabase.child("userdeviceid").child(userId).setValue(device);
        mDatabase.child("users").child(userId).setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                startActivity(new Intent(StartServer.this, MainActivity.class));
                saveIsLoggedIn(true);
                finish();
            }
        });
    } else {
        Toast.makeText(context, getString(R.string.signerror), Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(StartServer.this, StartServer.class);
        startActivity(intent);
    }

}

Advertisement

Answer

It’s hard to say anything concrete about the cause without knowing how those 1% users are different from the other 99%.

One step that might help in troubleshooting is to first detect whether the client is connected to the database backend before writing to the database. While observing this .info/connected node won’t change anything about the behavior, it might allow you to see if the connection state makes any difference for who is experiencing the problems.

You’ll need another place to log data for folks who are not connected to the database, so consider logging both the connection state and the completion of the write to something like Google Analytics, or some other location that is not dependent on the database itself.

Advertisement