Last active
August 31, 2020 06:12
-
-
Save LishuGupta652/3d2f796054c1f06e541057b1c467049e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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