Firebase "Реактивно-асинхронная хранение/асинхронное хранилище"Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Firebase "Реактивно-асинхронная хранение/асинхронное хранилище"

Сообщение Anonymous »

Я использую Firebase в нативном проекте React (с включенной Expo + Hermes). Я настроил Aurt Firebase Auth с AsyncStorage для постоянства, но я сталкиваюсь с следующими проблемами:
Журналы ошибок:

Код: Выделить всё

You are initializing Firebase Auth for React Native without providing
AsyncStorage. Auth state will default to memory persistence and will not
persist between sessions. In order to persist auth state, install the package
"@react-native-async-storage/async-storage" and provide it to
initializeAuth:

import { initializeAuth, getReactNativePersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
const auth = initializeAuth(app, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage)
});
ERROR  [runtime not ready]: Error: Component auth has not been registered yet, js engine: hermes
Это мой файл firebase.ts
import { initializeApp, getApp } from "firebase/app";
import { getStorage } from "firebase/storage";
import { initializeFirestore } from "firebase/firestore";
import { initializeAuth, getAuth } from "firebase/auth";
import { Platform } from "react-native";

const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: "",
};

console.log("🔥 Firebase Service: Starting initialization...");

// Initialize Firebase App
console.log("🔥 Firebase Service: Initializing Firebase app...");
const app = initializeApp(firebaseConfig);
console.log("🔥 Firebase Service: Firebase app initialized successfully");

// Initialize Auth with proper persistence for React Native
console.log("🔥 Firebase Service: Initializing Firebase Auth...");
let auth;
if (Platform.OS === "web") {
auth = getAuth(app);
} else {
try {
const ReactNativeAsyncStorage =
require("@react-native-async-storage/async-storage").default;
const { getReactNativePersistence } = require("firebase/auth");
auth = initializeAuth(app, {
persistence: getReactNativePersistence(ReactNativeAsyncStorage),
});
} catch (error) {
console.warn(
"🔥 Firebase Service: Failed to initialize auth with persistence, falling back to default:",
error
);
auth = getAuth(app);
}
}

export { auth };
// Use initializeFirestore to specify the region (asia-south1 for Mumbai)
console.log("🔥 Firebase Service: Initializing Firestore...");
export const db = initializeFirestore(app, {
host: "asia-south1-firestore.googleapis.com",
ssl: true,
});
console.log("🔥 Firebase Service: Firestore initialized successfully");

console.log("🔥 Firebase Service: Initializing Storage...");
export const storage = getStorage(app);
console.log("🔥 Firebase Service: Storage initialized successfully");

console.log(
"🔥 Firebase Service: All Firebase services initialized successfully!"
);

// Export both the auth instance and getAuth function
export { app, getApp };

export default app;
< /code>
Что я попробовал:
установлен @React-cnync-storage /async-storage ✅ < /p>
Убедитесь, что Hermes правильно настроен ✅ < /p>
Использование initizeauth () для реагирования. Предупреждение?>

Подробнее здесь: https://stackoverflow.com/questions/796 ... rage-issue
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»