2016-07-02 8 views
2

私の方法でパスワードを忘れる方法を実装するにはどうすればいいですか?私は間もなく予定されているHTMLプロジェクトを作成しています。私のコード:あなたが忘れてしまったパスワードボタンを実装するには、私にGoogle Firebaseパスワードを忘れる

答えて

7

を助けることができる、あなたが呼び出す必要があり https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password してください:ここで

function toggleSignIn() { 
    if (!firebase.auth().currentUser) { 
// [START createprovider] 
var provider = new firebase.auth.GoogleAuthProvider(); 
// [END createprovider] 
// [START addscopes] 
provider.addScope('https://www.googleapis.com/auth/plus.login'); 
// [END addscopes] 
// [START signin] 
firebase.auth().signInWithPopup(provider).then(function(result) { 
    // This gives you a Google Access Token. You can use it to access the Google API. 
    var token = result.credential.accessToken; 
    // The signed-in user info. 
    var user = result.user; 
    // [START_EXCLUDE] 
    document.getElementById('quickstart-oauthtoken').textContent = token; 
    // [END_EXCLUDE] 
}).catch(function(error) { 
    // Handle Errors here. 
    var errorCode = error.code; 
    var errorMessage = error.message; 
    // The email of the user's account used. 
    var email = error.email; 
    // The firebase.auth.AuthCredential type that was used. 
    var credential = error.credential; 
    // [START_EXCLUDE] 
    if (errorCode === 'auth/account-exists-with-different-credential') { 
    alert("You have already signed up with a different auth provider for that email."); 
    // If you are using multiple auth providers on your app you should handle linking 
    // the user's accounts here. 
    } 
else if (errorCode === 'auth/auth-domain-config-required') { 
alert("An auth domain configuration is required"); 
    } 
    else if (errorCode === 'auth/cancelled-popup-request') { 
     alert("Popup Google sign in was canceled"); 
    } 
    else if (errorCode === 'auth/operation-not-allowed') { 
     alert("Operation is not allowed"); 
    } 
    else if (errorCode === 'auth/operation-not-supported-in-this-environment')  { 
     alert("Operation is not supported in this environment"); 
    } 
    else if (errorCode === 'auth/popup-blocked') { 
     alert("Sign in popup got blocked"); 
    } 
    else if (errorCode === 'auth/popup-closed-by-user') { 
     alert("Google sign in popup got cancelled"); 
    } 
    else if (errorCode === 'auth/unauthorized-domain') { 
     alert("Unauthorized domain"); 
    } 
    else { 
    console.error(error); 
    } 
    // [END_EXCLUDE] 
    }); 
    // [END signin] 
    } else { 
    // [START signout] 
    firebase.auth().signOut(); 
    // [END signout] 
    } 
    // [START_EXCLUDE] 
    document.getElementById('quickstart-sign-ing').disabled = false; 
    // [END_EXCLUDE] 
} 

はあなたに指導をするためのリンクです firebase.auth().sendPasswordResetEmail('[email protected]')

チェック詳細のドキュメント: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#sendPasswordResetEmail

+0

こんにちは。 firebase auth apiを使ってパスワードを忘れた機能を実装しています。 sendPasswordResetEmail()関数を使用するとうまくいきます。 firebase api docは「パスワードリセットを完了するには、ユーザーに指定された新しいパスワードとともに、ユーザーに送信された電子メールで提供されたコードでfirebase.auth.Auth#confirmPasswordResetを呼び出します。 今、私はconfirmPasswordReset()関数のparamを知りたいと思います。 confirmPasswordReset(code)、ここでコードはどこから来ますか? –

+0

パスワードリセット電子メールリンクからそのコードを解析する必要があります。ユーザーはそのページをクリックします。また、独自のランディングページをホスティングしている場合にも関連します。 Firebaseコンソールでそれを変更する必要があります。 – bojeil

関連する問題