0

일부 매개 변수를 가져와 firebase에서 암호 기능을 재설정하려고합니다. 내가 mode, oobCodeapiKey을 얻고 싶은 http://localhost:8080/passwordreset?mode=resetPassword&oobCode=y6FIOAtRUKYf88Rt5OlEwxUuTyEmb3M4gquZSIseX2UAAAFevpj-gw&apiKey=AIzaSyBaCCvq-ZEfQmdrL7fmElXDjZF_J-tku2I매개 변수를 가져 와서 내 메서드에서 사용할 변수에 저장하고 사용하십시오.

:처럼 내 링크의 모양을

이입니다. 중포 기지 문서에서

export default { 


data: function() { 
    return { 
     passwordNew: '', 
     passwordConfirm: '', 
     mode:'', 
     actionCode: '', 
     continueUrl: '', 
    } 
}, 
methods: { 
    handleResetPassword: function() { 
     var accountEmail; 

     firebase.auth().verifyPasswordResetCode(actionCode).then(function(email) { 
      var accountEmail = email; 
      firebase.auth().confirmPasswordReset(this.actionCode, this.passwordNew).then(function(resp) { 

       alert("Password reset success"); 
       this.$router.push('hello') 
      }).catch(function(error) { 
       // Error occurred during confirmation. The code might have expired or the 
       // password is too weak. 
       console.log("error 1") 
      }); 
     }).catch(function(error) { 
      // Invalid or expired action code. Ask user to try to reset the password 
      // again. 
      console.log("error 2") 
     }); 
    }, 
} 

} 
+1

가능한 복제 [? 콜백 내에서 올바른 \ '이 \를'에 액세스하는 방법 (https://stackoverflow.com/questions/20279484/how-to : 내보내기 기본에서

-access-the-correct-this-inside-a-callback) – Bert

+0

@Bert에게 도움을 주셔서 감사합니다. 그러나 이것이 중복이라고 생각하지 않습니다. – Muli

+0

적어도 부분적으로는 위의 코드 중 아무 것도 작동하지 않습니다. 'then' 콜백에서'function() {}'을 사용하기 때문에 데이터 프로퍼티에 접근 할 수 없습니다. 화살표 함수, 클로저 또는 바인딩을 사용해야합니다. – Bert

답변

1

: 이러한 사용자의 이메일 주소 를 업데이트하고 사용자의 암호를 재설정 등

일부 사용자 관리 작업, 전자 메일이 전송되는 결과 여기 내가 지금 무엇을 가지고 사용자에게 이 이메일에는 수신자가 열어 을 완료하거나 사용자 관리 작업을 취소 할 수있는 링크가 있습니다. 기본적으로 사용자 관리 이메일은 프로젝트의 Firebase Hosting 도메인에있는 URL에 호스트 된 웹 페이지 인 기본 작업 처리기로 연결됩니다.

링크 : https://firebase.google.com/docs/auth/custom-email-handler

당신은 중포 기지 문서에서 내가 그 조각을 가지고 그냥 getParameterByName 기능 썼다, 그 매개 변수를 가져 변수에 저장할 필요가 : 당신은 얻을 필요가

function getParameterByName(name){ 
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regexS = "[\\?&]"+name+"=([^&#]*)"; 
    var regex = new RegExp(regexS); 
    var results = regex.exec(window.location.href); 
    if(results == null) 
    return ""; 
    else 
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
} 
    // Get the action to complete. 
    var mode = getParameterByName('mode'); 
    // Get the one-time code from the query parameter. 
    var actionCode = getParameterByName('oobCode'); 
    // (Optional) Get the continue URL from the query parameter if available. 
    var continueUrl = getParameterByName('continueUrl'); 

을 이러한 매개 변수를 먼저 확인하고 verifyPasswordResetCode 메서드에서 동작 코드를 확인한 다음 암호를 변경하고 동작 코드와 함께 메서드에 저장합니다.

data: function() { 
     return { 
      passwordNew: '', 
      passwordConfirm: '', 
      mode: mode, 
      actionCode: actionCode, 
      continueUrl: continueUrl, 
     } 
    }, 
    methods: { 
     handleResetPassword: function() { 
      var passwordNew = this.passwordNew 
      var actionCode = this.actionCode 
      firebase.auth().verifyPasswordResetCode(actionCode).then(function(email) { 
       console.log("ActionCode: "+ actionCode); 

       firebase.auth().confirmPasswordReset(actionCode, passwordNew).then(function(resp) { 

        alert("Password reset success"); 
        this.$router.push('hello') 
       }).catch(function(error) { 
        console.log("error 1"+ error) 
       }); 
      }).catch(function(error) { 
       console.log("Action code is invalid"+ error) 
      }); 

     }, 
    } 
+0

고맙습니다. – Muli