Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My app.js

JavaScript
import '../styles/globals.css';
import {useAuthState} from "react-firebase-hooks/auth";
import { auth, db } from '../firebase';
import Login from './login';
import Loading from '../components/Loading';
import { initializeApp } from 'firebase/app';
import {useEffect} from "react" 


function MyApp({ Component, pageProps }) {

  const [user, loading] = useAuthState(auth);

  useEffect(() => {
    if (user) {
      db.collection('users').doc(user.uid).set(
        {
        email: user.email,
        lastSeen: firebase.firestore.FieldValue.serverTimestamp(),
        photoURl: user.photoURL,
      }, {merge: true}
      );
    }
  }, [user])

  if(loading) return <Loading />
  if(!user) return <Login/>

  return <Component {...pageProps} />
}

export default MyApp


What I have tried:

I used useEffect as seen above, I'm pretty sure the code from firebase has changed and therefor I am getting an error, that db.collection is not a function.

How can I change the code above to get user-email, last seen status and photo from logged in user? I did check firebase documentation but couldn't find anything useful.
Posted
Updated 29-Apr-22 2:15am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900