如何防止dynamicLink侦听器在react-native中多次触发?

问题描述 投票:0回答:1

我已在我的本机应用程序中从firebase启用signInWithEmailLink()。>

一切都成功进行,还创建了用户,但是我认为onLink(handleLink)侦听器被多次触发,甚至在用户登录后也会导致错误。

日志:

link is tru
 LOG  email:  [email protected] //I have hidden the actual email
 LOG  email:  [email protected]
 LOG  email:  [email protected]
 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);

非常感谢您的帮助

我已在我的本机应用程序的firebase中启用signInWithEmailLink()。一切都成功完成,还创建了用户,但是我认为onLink(handleLink)侦听器被触发了多个...

react-native firebase-authentication firebase-dynamic-links react-native-firebase
1个回答
0
投票

由于console.log('email: ', email);被调用了3次,所以我假设console.log('link is tru');也被调用了3次,所以问题是整个handleLink函数在auth().signInWithEmailLink完成之前被调用了3次。

© www.soinside.com 2019 - 2024. All rights reserved.