Код: Выделить всё
import firebase from "firebase/compat/app";
import 'firebase/compat/firestore'
import 'firebase/compat/auth'
import { getReactNativePersistence, setPersistence } from 'firebase/auth';
import ReactNativeAsyncStorage from '@react-native-async-storage/async-storage';
const localPersistence = getReactNativePersistence(ReactNativeAsyncStorage);
const firebaseConfig = {
apiKey: "key",
authDomain: "domain",
databaseURL: "url",
projectId: "id",
storageBucket: "bucket",
messagingSenderId: "id",
appId: "id",
measurementId: "id"
};
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig);
}
export const auth = firebase.auth();
export const firestore = firebase.firestore();
Код: Выделить всё
import { auth } from '../../firebase.js'
export default function SignIn({ navigation }) {
const [email, setEmail] = useState(null);
const [password, setPassword] = useState(null);
const onLogin = async () => {
if(!email || !password){
return;
}
auth.signInWithEmailAndPassword(email, password)
.then((userCredential) => {
const user = userCredential.user;
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
console.log("error while user logs in: ", error);
if(errorCode === "auth/invalid-credential"){
setError("The supplied auth credential is incorrect, malformed or has expired.")
}else{
setError("An error occured and we can not log you in.")
}
});
};
return (
);
}
< /code>
Я попытался позвонить < /p>
const authState = firebase.auth();
authState.setPersistence(localPersistence);
export const auth = authState;
Как я уже сказал, документация использует Firebase/Auth , в то время как я использую Firebase/Compat/Auth . Кто -нибудь может посоветовать? Для меня очень важно держать пользователя в приложении.
Подробнее здесь: https://stackoverflow.com/questions/794 ... ompat-auth