将URL分配给firebaseauth photoURL

时间:2018-09-18 12:02:25

标签: angular firebase firebase-authentication angularfire2

我想使用angularfirebase auth photoUrl存储用户图像的URL。 我已经可以存储名称了,但是如果我想存储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

0 个答案:

没有答案