Expo SDK 48破坏了Firebase Auth。

huangapple go评论51阅读模式
英文:

Expo SDK 48 broke Firebase Auth

问题

我刚刚升级到Expo SDK 48,似乎每次刷新后都会注销我的登录状态。我降级回SDK 47,一切都正常工作。我使用的是firebase v9(v9.17.1),通过expo install而不是yarn进行安装。

我升级到Expo 48的步骤如下:

  • 更新到最新版本的EAS CLI:npm i -g eas-cli。
  • 安装新版本的Expo包:yarn add expo@^48.0.0。
  • 升级所有依赖以匹配SDK 48:npx expo install --fix。
  • 检查项目依赖中可能存在的问题:npx expo-doctor。
  • 升级到最新版本的firebase web sdk:expo install firebase。
  • 删除node modules、yarn.lock文件并重新安装所有内容。

我漏掉了什么?

我在发布说明中找不到可以帮助我的信息。

英文:

I have just upgraded to Expo SDK 48 and it seems I am logged out after every refresh.
I downgraded back to SDK 47, and everything works as expected.
I am using firebase v9 (v9.17.1), installed with expo install not with yarn.

Steps I followed for upgrading to Expo 48:

  • Update to the latest version of EAS CLI: npm i -g eas-cli.
  • Install the new version of the Expo package: yarn add expo@^48.0.0
  • Upgrade all dependencies to match SDK 48: npx expo install --fix
  • Check for any possibly issues in your project dependencies: npx
    expo-doctor
  • Upgraded to the latest version of the firebase web sdk: expo install firebase
  • delete node modules, yarn.lock and reinstall everything

What am I missing ?

I could't find anything on the release notes that can help me.

答案1

得分: 13

我认为我找到了问题。Firebase使用了一个已弃用的AsyncStorage版本,显然在SDK 48中被移除。

我能够通过以下方式修复它(更多测试正在进行中):

import AsyncStorage from "@react-native-async-storage/async-storage";

import {getReactNativePersistence, initializeAuth} from 'firebase/auth/react-native';

initializeAuth(app, {
  persistence: getReactNativePersistence(AsyncStorage);
});

通过persistence选项,您告诉Firebase使用“本地”AsyncStorage,即当前RN应用中存在的AsyncStorage。

英文:

I think I found the problem. Firebase uses a deprecated version of AsyncStorage, which apparently was removed in SDK 48.

I was able to fix it (more testing is ongoing) with this:

import AsyncStorage from "@react-native-async-storage/async-storage";

import {getReactNativePersistence, initializeAuth} from 'firebase/auth/react-native';

initializeAuth(app, {
  persistence: getReactNativePersistence(AsyncStorage);
});

With the persistence node, you tell Firebase to use the "native" AsyncStorage, i.e. the AsyncStorage that is present in current RN apps.

答案2

得分: 0

请看一下捕获登录事件(onAuthStateChanged())的代码,以及您如何缓存其结果(通常是通过设置状态变量中的user值),然后查看您的应用在代码刷新发生时的行为。

我敢打赌,这可能是 Expo 48(或更可能是其底层的 React 或 React-Native 版本)中的行为变化,但这并不是“错误”的。相反,我敢打赌,您的代码在 48 版之前“运行正常”,但实际上并不正确。

考虑发布一些关于您如何调用 onAuthStateChanged() 以及如何使用其返回值来呈现您的用户界面的代码。

英文:

Take a look at the code where you are capturing the login event (onAuthStateChanged()) and how you are caching its results (typically by setting the user value in a state variable) and see how your app is behaving when code refreshes are happening.

My bet is that this might be a behaviour change in how Expo 48 (or more likely its underlying React or React-Native version) has, but that it isn't "wrong". Instead, my bet is that your code was "working" under pre-48 but that it wasn't/isn't actually correct.

Consider posting some code around where/how you are calling onAuthStateChanged(), and how you are using the value returned by it to render your UI.

huangapple
  • 本文由 发表于 2023年2月26日 20:51:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572098.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定