[英]Vite + Vue3 + CapacitorJS + Firebase on iOS is not passing through Authentication
我正在使用连接到 Firebase Web SDK 9 的 Vite+Vue3 并希望使用电容器构建移动应用程序。
Web 和 Android 上的一切都按预期工作,但是当我到达 iOS 时,我似乎无法通过身份验证(仅限电子邮件/密码)。
我的登录视图有我的登录 function 如下;
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();
}
}
});
在本地运行或在托管的 firebase 站点上运行时,web 一切都按预期工作,我可以看到所有这些控制台日志,如您所料。
虽然在 iOS 上; 当我单击表单上的提交时,我得到一些 iOS 样式的错误(我将在下面粘贴),但没有别的。 我真的缺乏 iOS 开发和 XCode 的经验,所以也许我只是缺少一些东西。
这是来自 iOS 仿真器的控制台 output;
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 的错误消息; 所以至少那部分是有效的
任何关于如何进步的想法或建议将不胜感激!
谢谢克里斯
好吧,对于那些将来遇到这个问题的人,我发现这个问题与 Firebase SDK v9 和电容器有关。
解决方案是在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();
有完全相同的问题,上面的修复似乎不是一个修复。 可以登录,但似乎无法使用 setDoc 更新任何内容或使用 getDoc 检索...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.