【问题标题】:Vite + Vue3 + CapacitorJS + Firebase on iOS is not passing through AuthenticationiOS 上的 Vite + Vue3 + CapacitorJS + Firebase 未通过身份验证
【发布时间】:2022-08-24 04:50:29
【问题描述】:

我正在使用连接到 Firebase Web SDK 9 的 Vite+Vue3,并希望使用 Capacitor 构建移动应用程序。

Web 和 Android 上的一切都按预期工作,但是当我进入 iOS 时,我似乎无法通过身份验证(仅限电子邮件/密码)。

我的登录视图具有以下登录功能;

const login = () => {
  signInWithEmailAndPassword(auth, email.value, password.value)
    .then((userCredential) => {
      console.log(\"First message not sent to console\");
      // Signed in
      const user = userCredential.user;
    })
    .catch((error) => {
      const errorCode = error.code;
      const errorMessage = error.message;
      console.log(error.message);
    });
};

然后我在我的 App.vue

onAuthStateChanged(auth, (user) => {
  console.log(\"onAuthStateChanged FIRED\");
  if (user) {
    const uid = user.uid;
    console.log(\"⏱ State Changed\");
    if (!store.user.uid) {
      store.setUser(user);

      console.log(\"⏱ We have an UID\");
    }
  } else {
    if (store.user.uid) {
      store.clearUser();
    }
  }
});

在本地运行或在托管的 web 的 firebase 站点上运行时,一切都按预期工作,我可以看到所有这些控制台日志,如您所料。

不过在 iOS 上;当我单击表单上的提交时,我得到一些 iOS 样式的错误(我将在下面粘贴),但没有别的。我真的缺乏 iOS 开发和 XCode 的经验,所以也许我只是错过了一些东西。

这是 iOS 模拟器的控制台输出;

2022-04-26 23:05:05.944955+1000 App[15964:3664648] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///Users/chriswinfield-blum/Library/Developer/CoreSimulator/Devices/AE7A6476-24EF-4008-BD6E-BEDE553DA029/data/Containers/Data/Application/0001144C-40AF-4252-BB97-52BA69BEBA82/Library/Cookies/app.meditimer.www.binarycookies
⚡️  Loading app at capacitor://localhost...
⚡️  WebView loaded
⚡️  [log] - ⏱  Login component mounted!
objc[15964]: Class _PathPoint is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x12221f338) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x13e020fe8). One of the two will be used. Which one is undefined.
objc[15964]: Class _PointQueue is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore (0x12221f310) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextInputUI.framework/TextInputUI (0x13e021010). One of the two will be used. Which one is undefined.

我怀疑 pinia 不兼容,但我只是存储用户集合和 isLoggedIn 标志,所以认为没关系(特别是考虑到我正在连接到本地存储)但我没有看到任何控制台输出,所以现在已经排除了它(可能是明天的问题!)

有趣的是,当我通过发送错误的电子邮件/密码时;我确实可以看到来自 firebase 的错误消息;所以至少那部分是有效的

任何关于如何进步的想法或建议将不胜感激!

谢谢 克里斯

    标签: javascript firebase firebase-authentication vuejs3 capacitor


    【解决方案1】:

    好吧,对于那些将来遇到这个问题的人,我发现这个问题与 Firebase SDK v9 和 Capacitor 有关。

    解决方案是在Capacitor.isNativePlatform() === true 时使用initializeAuth 而不是getAuth

    function whichAuth() {
      let auth;
      if (Capacitor.isNativePlatform()) {
        auth = initializeAuth(app, {
          persistence: indexedDBLocalPersistence,
        });
      } else {
        auth = getAuth(app);
      }
      return auth;
    }
    
    const auth = whichAuth();
    

    【讨论】:

      【解决方案2】:

      有完全相同的问题,上面的修复似乎不是一个修复。可以登录,但似乎无法使用 setDoc 更新任何内容或使用 getDoc 检索...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-26
        • 1970-01-01
        • 1970-01-01
        • 2021-10-11
        相关资源
        最近更新 更多