0

I am making a React Native app. I have been implementing Anonymous Login when user enters the app. After certain action, user can signup. When I try to link the current anonymous user with email and password, it says [StitchServiceError: invalid username/password]. I don't know why. I have been following the exact same documentation to linkWithCredential.

Here is my code:

const auth = Stitch.defaultAppClient.auth;
const collection = Stitch.defaultAppClient
      .getServiceClient(RemoteMongoClient.factory, 'mongodb-atlas')
      .db('snack')
      .collection('users');
const {email, password, ...rest} = currentUser;
return from(
      auth.user.linkWithCredential(
        new UserPasswordCredential(email, password),
      ),
    ).pipe(switchMap(() => .....))

I am using Redux Observable for side effects.

I have enabled Email/Password and Anonymous Authentication in the settings. I don't know what is wrong here and why is it giving me username and password error when I am trying to signup and link the user.

Parth Chokshi
  • 642
  • 4
  • 16

1 Answers1

0

Ah, silly. I am coming from Firebase background. So thought it would work the same way. But it doesn't.

So, I have to create an account first. And then link it. In Firebase. you can directly link the account and they create a new account and link it with your anonymous session automatically.

Here is the updated code:

const {email, password, ...rest} = currentUser;

const emailPasswordClient = Stitch.defaultAppClient.auth.getProviderClient(
      UserPasswordAuthProviderClient.factory,
    );

    return from(
      emailPasswordClient.registerWithEmail(email, password),
    ).pipe(
      switchMap(() => {
        return from(
          auth.user.linkWithCredential(
            new UserPasswordCredential(email, password),
          ),
        ).pipe(
          switchMap(() => ...)
.....)
Parth Chokshi
  • 642
  • 4
  • 16