Как предотвратить прослушивание динамического слушателя несколько раз в реагировать на родной? - PullRequest
0 голосов
/ 10 января 2020

Я включил signInWithEmailLink() из firebase в моем приложении-реактиве.

Все работает успешно, пользователь также создан, но я думаю, что прослушиватель onLink(handleLink) запускается несколько раз и приводит к ошибка даже после входа пользователя в систему.

Журналы:

link is tru
 LOG  email:  email@gmail.com //I have hidden the actual email
 LOG  email:  email@gmail.com
 LOG  email:  email@gmail.com
 LOG  USer created
 LOG  EROR:  [Error: [auth/invalid-action-code] The out of band code is invalid. This can happen if the code is malformed, expired, or has already been used.]
 LOG  EROR:  [Error: [auth/invalid-action-code] The out of band code is invalid. This can happen if the code is malformed, expired, or has already been used.]
 LOG  EROR:  [Error: [auth/invalid-action-code] The out of band code is invalid. This can happen if the code is malformed, expired, or has already been used.]

Как вы можете видеть, как это происходит несколько раз, как я могу предотвратить это ??

Это мой код:

const handleLink = async link => {
  console.log('opened Link: ', link.url);
  if (auth().isSignInWithEmailLink(link.url)) {
    console.log('link is tru');
    try {
      const email = await AsyncStorage.getItem('email');
      console.log('email: ', email);
      await auth()
        .signInWithEmailLink(`${email}`, link.url)
        .then(() => {
          console.log('USer created');
        })
        .catch(err => {
          console.log('EROR: ', err);
        });
    } catch (err) {
      console.log('err: ', err);
    }
  } else {
    console.log('link is false');
  }
};

const link = dynamicLinks().onLink(handleLink);

Помощь будет очень признателен

1 Ответ

0 голосов
/ 11 января 2020

Поскольку console.log('email: ', email); вызывается 3 раза, я предполагаю, что console.log('link is tru'); также вызывается 3 раза, поэтому проблема в том, что вся функция handleLink вызывается 3 раза до завершения auth().signInWithEmailLink.

...