JavaScript

PHOTO EMBED

Sat May 22 2021 13:47:48 GMT+0000 (UTC)

Saved by @minhhung1106 #javascript

var firebaseConfig = {
apiKey: "AIzaSyBrZb4v8u3ht6VG6yzAC3fc0UZ6HF5Ypk",
authDomain: "upload-c77ba.firebaseapp.com",
projectId: "upload-c77ba",
storageBucket: "upload-c77ba.appspot.com",
messagingSenderId: "712086498758",
appId: "1:712086498758:web:ae2f17977cc95d3b8cd6c7",
measurementId: "G-9JYB3GET1V"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

let profileView = document.getElementById('profile-view');
let signupView = document.getElementById('signup-view');
let email = document.getElementById('email');
let prord = document.getElementById('pword');
let img = document.getElementById('img');

let file = {};

function chooseFile(e) {
file = e.target.files[0];
}

function signUpButtonPressed(e) {
firebase.auth().createUserWithEmailAndPassword(email.value, pword.value)
.then(auth => {
firebase.storage().ref('users/' + auth.user.uid + '/profile.jpg').put(file).then(() => {
console.log('success!');
}).catch(err => {
console.log(err);
})
}).catch(err => {
console.log(err.message);
})
}

firebase.auth().onAuthStateChanged(user => {
if (user) {
firebase
.storage()
.ref("users")
.child(user.uid + "/profile.jpg")
.getDownloadURL()
.then(imgUrl => {
img.src = imgUrl;
});
console.log(user)
} else {
signupView.style.visibility = 'visible';
profileView.style.visibility = 'hidden';
}
})

function signOutButtonPressed() {
firebase.auth().signOut();
}
content_copyCOPY