iOS上的Vite + ve3 + CapacitorJS + Firebase不通过认证



我正在使用Vite+ ve3连接到Firebase Web SDK 9,并希望使用电容器构建移动应用程序。

在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();
}
}
});

当在本地运行或在托管的firebase站点上运行web时,一切都如预期的那样工作,并且我可以看到您期望的所有控制台日志。

在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看到我的错误消息;所以至少那部分是有效的

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

谢谢克里斯。

好的,对于那些在未来遇到这个问题的人,我发现这个问题与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();

最新更新