首页 > 解决方案 > 提供给 SecureStore 的密钥无效

问题描述

我收到以下错误

未处理的承诺拒绝:错误:提供给 SecureStore 的密钥无效。键不能为空,并且只能包含字母数字字符、“.”、“-”和“_”。

我的代码:

function onpresscard(item) {
    const lang = item.code;
    firebase
      .firestore()
      .collection(`mechphone`)
      .add({
        phonenumber: phonenumber,
      })
      .then((docRef) => {
        const id = docRef.id;
        const pid = phonenumber+'id';
        const langcode = phonenumber+'lang';
        save(pid, langcode, id, lang);
      }).then(()=>{
        navigation.replace("AppNavigator");
      }).catch((error) => {
        console.error("Error adding document: ", error);
      });
  }

async function save(pid, langcode, id, lang) {
    console.log(pid, langcode, id, lang, "inside saveid");

    try {
      await SecureStore.setItemAsync(pid, id);
      await SecureStore.setItemAsync(langcode, lang);
    } catch (error) {
      console.log(error);
    }
}

onpresscard 函数在按钮单击时调用。我得到了预期值 docRef.id 并能够使用以下参数将值传递给保存函数。再次在保存函数中收到它,并且 console.log(pid, langcode, id, lang, "inside saveid") 清楚地显示了字母数字而不是空的值。

如何避免这个错误?

我正在使用 expo react native - Android 模拟器

标签: react-nativegoogle-cloud-firestoreexpo

解决方案


推荐阅读