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

user.linkCredentials doesn't update user identities #5732

Open
thecoorum opened this issue Apr 14, 2023 · 5 comments
Open

user.linkCredentials doesn't update user identities #5732

thecoorum opened this issue Apr 14, 2023 · 5 comments

Comments

@thecoorum
Copy link

thecoorum commented Apr 14, 2023

How frequently does the bug occur?

Always

Description

While using Realm in React Native with @realm/react I noticed an issue with linking credentials. I'm registering a new user via email and password. As soon as the account confirmed the user can log in and it will try to link this credentials with initial anonymous user. This is done like

const user = useUser()

...

const handleLinkCredentials = useCallback(async (data) => {
  const credentials = Realm.Credentials.emailPasword(data.email, data.password)

  try {
    await user.linkCredentials(credentials)
  } catch (error) {
    ...
  }
}, [user])

If I log user.identities I will not see new identity as soon as email and password identity is linked. The new identity will appear after app reload, though

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

  1. Authorize user as anonymous
  2. Register email/password user
  3. Link existing anonymous user with newly created email/password user
  4. Log in with email/password user (?)

Not really sure if the last step is required

Version

11.8.0

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

iOS 16.2

Build environment

No response

Cocoapods version

No response

@kneth
Copy link
Contributor

kneth commented Apr 14, 2023

@thecoorum Thank you for reporting. I believe your observation is correct. You can try to call refreshCustomData() to update the identities.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Apr 14, 2023
@thecoorum
Copy link
Author

thecoorum commented Apr 14, 2023

Hey @kneth! Thanks for quick response, unfortunately this doesn't help. I'm logging user.identities and can see it doesn't even update any data after

await user.linkCredentials(credentials)
await app.logIn(credentials)

await user.refreshCustomData()

The combination like this also doesn't work for me

await user.linkCredentials(credentials)
await user.refreshCustomData()

await app.logIn(credentials)

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Apr 14, 2023
@thecoorum
Copy link
Author

@kneth from the other side I was able to achieve desired behavior by checking if the screen that shows identities is focused and refreshing customer data if so. But I'm aware that I can easily reach API requests limit using this technique. In the issue I described above user is signing in on another screen and then redirected to the settings where he/she can see current email.

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label May 31, 2023
@hysasuke
Copy link

@kneth from the other side I was able to achieve desired behavior by checking if the screen that shows identities is focused and refreshing customer data if so. But I'm aware that I can easily reach API requests limit using this technique. In the issue I described above user is signing in on another screen and then redirected to the settings where he/she can see current email.

Hi, I don't know if you have found the solution or not. I was facing the same issue today, my workaround is, after I call linkCredentials function, I reset the navigation to user's profile page (I'm using React-Navigation) by calling navigation.reset function, then, the page will rerender, and I'm able to get the latest user's profile by assigning app.currentUser to the user variable.

@eltonmorais
Copy link

Apparently, when you create the new credential the tolen changes. So, before try to link the credentials you should refreshCustomData():

This way worked for me (Flutter, but probably the same issue):

final authProvider = EmailPasswordAuthProvider(app);
await authProvider.registerUser(email, password);
final credentials = Credentials.emailPassword(email, password);
await userRealm.refreshCustomData();
await userRealm.linkCredentials(credentials);

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

4 participants