Skip to content

Instantly share code, notes, and snippets.

@mrcflorian
Last active July 2, 2020 19:28
Show Gist options
  • Save mrcflorian/b93251517dd6239848f8a66ec6160a39 to your computer and use it in GitHub Desktop.
Save mrcflorian/b93251517dd6239848f8a66ec6160a39 to your computer and use it in GitHub Desktop.
...
import { firebase } from './src/firebase/config'
...
export default function App() {
...
if (loading) {
return (
<></>
)
}
useEffect(() => {
const usersRef = firebase.firestore().collection('users');
firebase.auth().onAuthStateChanged(user => {
if (user) {
usersRef
.doc(user.uid)
.get()
.then((document) => {
const userData = document.data()
setLoading(false)
setUser(userData)
})
.catch((error) => {
setLoading(false)
});
} else {
setLoading(false)
}
});
}, []);
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment