Dies ist Teil meiner App.js-Datei:
Code: Select all
import { auth } from './firebase.js'
import analytics from '@react-native-firebase/analytics';
const App = () => {
const [currentUser, setCurrentUser] = useState(null);
useEffect(() => {
(async () => {
if(currentUser){
console.log("I have current user: ", analytics())
try{
await analytics().setUserId(currentUser.uid)
console.log("all done")
}catch(error){
console.log("error while setting analytics user id: ", error);
}
}
})();
}, [currentUser]);
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((user) => {
if (user) {
setCurrentUser(user);
}
});
return () => unsubscribe();
}, []);
if(!currentUser){
return (
);
}
else{
return (
);
}
};
export default App;
Code: Select all
import firebase from "firebase/compat/app";
import 'firebase/compat/firestore'
import 'firebase/compat/auth'
const firebaseConfig = {
apiKey: "some_key",
authDomain: "some_domain",
databaseURL: "some_url",
projectId: "some_project_id",
storageBucket: "some_id",
messagingSenderId: "id",
appId: "id",
measurementId: "id"
};
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig);
}
const authState = firebase.auth();
export const auth = authState;
export const firestore = firebase.firestore();
Bitte verweisen Sie mich nicht auf die Dokumente, ich habe sie mehrmals gelesen, ich brauche eine praktische Lösung.