Skip to content

Instantly share code, notes, and snippets.

@LishuGupta652
Last active August 31, 2020 06:12
Show Gist options
  • Save LishuGupta652/3d2f796054c1f06e541057b1c467049e to your computer and use it in GitHub Desktop.
Save LishuGupta652/3d2f796054c1f06e541057b1c467049e to your computer and use it in GitHub Desktop.
// Firebase Storage :
const handleUpload = () => {
const uploadTask = storage.ref(`images/${image.name}`).put(image);
uploadTask.on(
'state_changed',
(snapshot) => {
// Progress funciton
const progress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
setProgress(progress)
}
)
}
// Firebase signup with email and password :
const signup = (e) => {
e.preventDefault();
auth
.createUserWithEmailAndPassword(email, password)
.then((authUser) => {
authUser.user.updateProfile({
displayName: username
})
})
.catch(err => alert(err.message))
setOpen(false)}
// Firebase SignIn with email and password :
const signin = (e) => {
e.preventDefault()
auth
.signInWithEmailAndPassword(email, password)
.then((authUser) => {
authUser.user.updateProfile({
displayName: username
})
})
.catch(err => alert(err.message))
setOpenSignIn(false)
}
// Retriving data from Firebase :
useEffect(() => {
db.collection('posts').orderBy('timestamp', 'desc').onSnapshot(snapshot => (
setPosts(snapshot.docs.map(doc => ({
id: doc.id,
post: doc.data()
})))
))
}, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment