App freezes when logging in with the same user

I have a pretty simple goal: re-validate a logged-in user’s email and password credentials before setting a new password.

The only way I’ve found to do this is to call app.logIn with the currentUser email and the password as entered by the user. If the credentials are valid, the app should proceed with a password reset, otherwise it would error. I already have a working “forgot password” flow, but I wanted a different flow for a user that’s already logged in involving re-validating the credentials.

The problem is that the app freezes when it gets to await app.logIn(<Valid Credentials>). It throws as expected if the credentials are invalid. I see a successful authorization in my Atlas log but the Promise never resolves.

Is there any way to achieve the desired effect of “re-validating” a logged-in user’s credentials?

Tech stuff:

  • I’m using app from the useApp hook, just as I am during the initial login
  • @realm/react”: “^0.5.2”
  • “react-native”: “^0.72.4”
  • “realm”: “^12.0.0”

Bumping for visibility. Can anyone help?

Hi Nick - would you be able to share a minimal repro case with us?

@mpobrien Thanks for the reply and sorry for the delay in my response

Below is the relevant parts for the “update password” screen. This is accessible when the user has already logged in.

const UpdatePasswordScreen = () => {
  const [currentPassword, setCurrentPassword] = useState('');
  const [password, setPassword] = useState('');
  const [confirmPassword, setConfirmPassword] = useState('');

  const user = useUser();
  const app = useApp();

  const validateCurrentPassword = useCallback(async () => {
     try {
       const credentials = Realm.Credentials.emailPassword({ email: user?.profile.email, password: currentPassword });
       await app.logIn(credentials); // app freezes here
       return true;
     } catch (error) {
       return false;
     }
   }, [app, user, currentPassword]);

  const handleSubmit = async () => {
    const isValid = await validateCurrentPassword();
    if (isValid) {
        const email = user?.profile.email;
        await app.emailPasswordAuth.callResetPasswordFunction({ email, password }, 'resetPassword', user?.id);
    }
  };
// ...render form
}

This actually worked as expected before I upgraded my npm packages, including Realm (I was prompted to upgrade in order to migrate from a partitioned sync to a flexible sync). I went from 10.24.0 to 12.0.0

Also of note, I’m not using the UserProvider fallback pattern, as this caused other problems. I’m not sure if it’s relevant, but since the issue seems to happen when trying to sign in with the same user that’s already signed in, I thought I’d mention it.

I have only checked this behavior on Android. It happens every time I try to validate the current user’s password as shown

Any suggestions or guidance?

@Nick_Martin I can’t think of why this would change, but perhaps there was a regression. Can you active logs at the top of your app?

import Realm from 'realm';
Realm.setLogLevel('trace');

We can then see if there are any oddities that occur and see how we can proceed further.

Unfortunately, every time I try to run the app with the log level set they way you said, it crashes the app before I can do anything. I can’t tell if this is a problem with Realm or my dev environment.

I set the log level to “debug” and here’s the whole log output after I press the submit button (that triggers the validation)

 LOG  [debug] App: log_in_with_credentials: app_id: homeschool-activity-tracker-kfbds
 LOG  [debug] App: version info: platform: Android  version: 31 - sdk: JS - sdk version: 12.0.0 - core version: 13.17.2
 LOG  [debug] App: request location: https://realm.mongodb.com/api/client/v2.0/app/homeschool-activity-tracker-kfbds/location
 LOG  [debug] App: update_hostname: https://realm.mongodb.com | wss://ws.realm.mongodb.com
 LOG  [detail] DB: 32129 Thread 129365459352816: Open file: /data/data/com.homeschoolactivitytracker/files/mongodb-realm/homeschool-activity-tracker-kfbds/server-utility/metadata/sync_metadata.realm
 LOG  [debug] DB: 32129 Thread 129365459352816: Query find all: 'identity == "6514e9b467771b4897d14c08" and provider_type == "local-userpass"', limit = -1
 LOG  [debug] DB: 32129 Thread 129365459352816: Query found: 1, Duration: 13 us
 LOG  [debug] DB: 32129 Thread 129365459352816: Initiate commit version: 729
 LOG  [debug] DB: 32129 Thread 129365459352816: Commit of size 2320 done in 3123 us

After logging this out a few times, I’m seeing that Initiate commit version changes every time but the Commit of size 2320 done is consistently where it stops

I still haven’t resolved this. open to any suggestions

@Nick_Martin Sorry for no response. We are trying to figure this out. There is a case where we want to update the refresh tokens before they expire, by essentially logging in again. This seems to lockup the UI for some reason and I believe it is related. If we get it fixed, I will be sure to update you!

Thanks for the update!

I was trying to replicate on a new tutorial app but i couldn’t get it to run in my dev environment!

I look forward to hearing the progress on that bug fix