Я хочу сохранить URL пользовательского изображения с помощью angularfirebase auth photoUrl.
Мне удалось сохранить имя, но если я хочу сохранить URL-адрес, он продолжает выдавать ошибку в консоли
photo_url не определено, не может прочитать значение userPhotoUrl
Это мой код
// url declaration
public userPhotoUrl;
public upload__profile__photo(fileUpload: maxPost){
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(`users_photos/${fileUpload.file.name}/`).put(fileUpload.file);
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) => {
uploadTask.snapshot.ref.getDownloadURL()
.then(downloadURL => {
this.userPhotoUrl = downloadURL;
});
});
}
// function to create user
public createUser(email: string, pass__word:string, userName:string){
this.username = userName;
this.email = email;
this.pass__word = pass__word;
firebase.auth().createUserWithEmailAndPassword(this.email,this.pass__word)
.then(function (response){
response.user.updateProfile({displayName:userName,photoURL:this.userPhotoUrl}).then(() =>{
console.log("this is the user id", response.user.uid);
console.log("this is the username", response.user.displayName);
console.log("this is the username", response.user.photoURL);
})
})
//but if i to hard code the url, i.e photoURL:"www.sample.com", it will work