realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.68k stars 562 forks source link

Realm app fails to authenticate users when running on Android emulator #6682

Open OzyOzk opened 1 month ago

OzyOzk commented 1 month ago

How frequently does the bug occur?

Always

Description

Hi all,

I'm unable to authenticate the realm user when I'm running my app on an Android Emulator. I keep getting the following errors;

 ERROR  [Realm.App - error] App: request location failed (CustomError -1): request to https://services.cloud.mongodb.com/api/client/v2.0/app/application-0-xxxxxx/location failed, reason: Network request failed      
 ERROR  [Realm.App - error] App: log_in_with_credentials failed: 0 message: request to https://services.cloud.mongodb.com/api/client/v2.0/app/application-0-xxxxxx/location failed, reason: Network request failed 

The authentication works when I use a physical device, but fails instantly when I run on an Emulator. I'm using the customJWT auth flow shown below;

const LogInScreen = () => {

  const {logInWithJWT, result} = useAuth();
  //const {logInWithAnonymous, result} = useAuth();

  const login = React.useCallback(async () => {
    try {
      var tokens = await SignInAzure();
      logInWithJWT(tokens["id_token"]);
    } catch (error) {
      console.log(error);
    }
  });

  return (
    <View>
      <Button title="Sign in to realm" onPress={login} />
    </View>
  );
};

LoginScreen is passed to my UserProvider like so;

<UserProvider fallback={<LogInScreen />}>

I've tried anonymous auth and email password authentication, both of which fail on emulator but succeed on a physical device.

Stacktrace & log output

ERROR  [Realm.App - error] App: request location failed (CustomError -1): request to https://services.cloud.mongodb.com/api/client/v2.0/app/application-0-xxxxxx/location failed, reason: Network request failed      
 ERROR  [Realm.App - error] App: log_in_with_credentials failed: 0 message: request to https://services.cloud.mongodb.com/api/client/v2.0/app/application-0-xxxxxx/location failed, reason: Network request failed

Can you reproduce the bug?

Always

Reproduction Steps

React Version 0.73.1 @realm/react - 0.7.0 realm: 12.9.0

Using a Pixel 5 emulator running platform version 34

    <AppProvider id={Config.REALM_APP_ID}>
      <UserProvider fallback={<LogInScreen />}>
        <RealmProvider
          sync={{
            flexible: true,
            initialSubscriptions: {
              update(subs, realm) {
                subs.add(realm.objects(TemplateOpportunity));
              },
            },
          }}
        >
          <GestureHandlerRootView>
            <NavigationContainer>
              <Tabs />
            </NavigationContainer>
          </GestureHandlerRootView>
        </RealmProvider>
      </UserProvider>
    </AppProvider>

Version

12.9.0

What services are you using?

Atlas Device Sync

Are you using encryption?

Yes

Platform OS and version(s)

Android SDK Version 34 & 33

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

sync-by-unito[bot] commented 1 month ago

➤ PM Bot commented:

Jira ticket: RJS-2821