Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.3 kB
4
Indexable
Never
// FIREBASE.JS FILE

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getFirestore } from 'firebase/firestore';

const firebaseConfig = {
  apiKey: process.env.REACT_APP_API_KEY,
  authDomain: process.env.REACT_APP_AUTH_DOMAIN,
  projectId: process.env.REACT_APP_PROJECT_ID,
  storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_APP_ID
};

const app = initializeApp(firebaseConfig);

export const auth = getAuth(app);
export const db = getFirestore(app);
export default app;

// .JSX file below

import { doc, getDoc } from "firebase/firestore";
import { UserAuth } from "../context/AuthContext";
import { db } from "../firebase";


export default function Card() {
  const { user } = UserAuth();
  console.log(user.uid)


  const getInfo = async() =>{
    const docRef = doc(db, "cities", "Y6Nmfp4N315IBG0ocUNr");
    const docSnap = await getDoc(docRef);
    if (docSnap.exists()) {
      console.log("Document data:", docSnap.data());
    } else {
      console.log("No such document!");
    }
  }
  
 
  return (
    <div className="">
      <h1 className="text-2xl font-bold">User: {user?.email}</h1>
    </div>
  );
}