Skip to content
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

UserProvider doesn't unmount Login-Component #6656

Closed
maierphilipp opened this issue May 5, 2024 · 7 comments
Closed

UserProvider doesn't unmount Login-Component #6656

maierphilipp opened this issue May 5, 2024 · 7 comments

Comments

@maierphilipp
Copy link

maierphilipp commented May 5, 2024

How frequently does the bug occur?

Always

Description

I have set up a React-Native-App with Expo SDK@50 and realm/@realm-react. This is the Code for my Custom-Provider:

import { RealmProvider, AppProvider, UserProvider } from "@realm/react";

// Models:
import { ShoppingItem } from "../models/ShoppingItem";

// Components:
import Login from "../components/login";

const appId = "myapp-*****";

export const RealmCustomProvider = ({ children }) => {
  return (
    <AppProvider id={appId}>
      <UserProvider fallback={Login}>
        <RealmProvider schema={[ShoppingItem]}>{children}</RealmProvider>
      </UserProvider>
    </AppProvider>
  );
};

The Login-Component uses the simple following Code:

import { useAuth, useUser } from "@realm/react";
import { useEffect } from "react";
import { Text, View } from "react-native";

const Login = () => {
  const { logInWithAnonymous } = useAuth();

  const guestLogin = () => {
    logInWithAnonymous();
  };

  return (
    <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
      <Text onPress={guestLogin}>Continue as Guest</Text>
    </View>
  );
};

export default Login;

After pressing the "Continue as Guest"-Button the App-Screen still shows the Login-Component. Checking the Users-Tab in the App-Services an anonymous user has been created. When reloading the App it just shows "Loading from Metro.." and gets stuck in the SplashScreen. After reinstalling or hard-closing and reopening the App the UserProvider recognizes the anonymous user and unmounts the Login-Component.

The Error reoccurs every single time. There is no error shown in the console. I already tried to reinstall all dependencies and even setting a whole blank app up. The error even occurs when I clone the Tutorials Github repository: https://github.com/notJust-dev/TrelloClone.

After trying to fix this error for two days I am nearly burned out and hope for some helpful responses! Thanks a lot in advance!

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

realm: 12.8.0, @realm/react: 0.6.2

What services are you using?

Atlas Device Sync

Are you using encryption?

No

Platform OS and version(s)

every IOS

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

Copy link

sync-by-unito bot commented May 5, 2024

➤ PM Bot commented:

Jira ticket: RJS-2816

@raininglemons
Copy link

Hi,

I've also been able to replicate this issue also. I'm using email - password login instead, and noticed when upgrading from [email protected] to any higher version the problem surfaces.

@realm/react doesn't seem to be the issue, as it works as expected with the last 2 versions along side [email protected].

With this simplified code:

  const signIn = useCallback(async () => {
    const creds = Realm.Credentials.emailPassword(
      email.toLowerCase(),
      password
    );
    console.log('Attempting login');
    try {
      await app.logIn(creds);
    } catch (e) {
      console.log('Login failed', e);
      throw e;
    } finally {
      console.log('Login ended');
    }
  }, [app, email, password]);

The whole app hangs when calling app.logIn. The catch and finally blocks are never reached and the UI becomes unresponsive.

Interestingly, the login is completing (presumably in the native code) as if you force exit the application then reopen it, you'll find the app in a logged in state.

In the meantime @maierphilipp you could try downgrading to [email protected]. If you're not using a barebones app, I'd also delete your ./ios and ./android folders to force expo to rebuild the app from scratch with the new dependencies.

@saravanakumargn
Copy link

Same issue here. Upto "realm": "^12.6.2" working fine. when I used "realm": "^12.7.0" logIn({email, password}) is working and screen goes main page. But, on the main page when I try to use const user = useUser(); user is always {}.

I Tried with the latest "realm": "^12.8.0", and after login screen freezes and if restart my app user is always {}

@maierphilipp
Copy link
Author

@raininglemons: Thank you so much! My problem is fixed with downgrading to v12.3.1!

@saravanakumargn: v12.3.1 with anonymous user gives me the logged-in user..

@greenafrican
Copy link

We're having the same issue using v12.8.0 and @realm/react v0.7.0 (and 0.6.1 same issue) and I've replicated it in the barebones todo RN example.

Not a big fan of having to constantly downgrade "stable" versions so would appreciate some feedback on this from the team. I'm pretty sure this was working a week or 2 ago so I'm wondering if anything has changed on the App Services side of the authentication? Just hard to think such a serious login issue been around since 12.3.1 (Nov 23, 2023)?

@elle-j @kraenhansen

@kneth
Copy link
Member

kneth commented May 14, 2024

I Tried with the latest "realm": "^12.8.0", and after login screen freezes

I believe it is related to realm/realm-core#7670. We have a fix, and we plan to release it later this week.

@kneth
Copy link
Member

kneth commented May 15, 2024

We have released Realm JS v12.8.1 which we believe will fix the issue. Please reopen if it is not the case.

@kneth kneth closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants