[英]Google Firebase forget password
你如何在我的方法中實現忘記密碼的方法。 我正在創建一個即將到期的 HTML 項目。 我的代碼:
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]
}
這是一個給你指導的鏈接: https://firebase.google.com/docs/auth/web/manage-users#set_a_users_password請你幫我
要實現忘記密碼按鈕,您必須調用: firebase.auth().sendPasswordResetEmail('user@example.com')
有關詳細信息,請查看文檔: https : //firebase.google.com/docs/reference/js/firebase.auth.Auth#sendPasswordResetEmail
實現恢復忘記密碼功能的最簡單方法是調用
import { AngularFireAuth } from "@angular/fire/auth";
constructor(
public afAuth: AngularFireAuth
) { }
// Reset Forggot password
ForgotPassword(passwordResetEmail) {
return this.afAuth.auth.sendPasswordResetEmail(passwordResetEmail)
.then(() => {
window.alert('Password reset email sent, check your inbox.');
}).catch((error) => {
window.alert(error)
})
}
要實現 firebase 重置,您首先需要將 email 發送給用戶,為此我們使用sendPasswordResetEmail方法。 之后,如果用戶點擊 email,它將被重定向到 firebase 提供的默認頁面,用戶可以從那里重置密碼。
但是,如果您想要自定義密碼重置頁面,您也可以這樣做,為此您需要更改 firebase 項目的 email 模板中的操作 url,然后您需要設置該自定義操作 url,為此您可以閱讀這個官方文檔頁面: https://firebase.google.com/docs/auth/custom-email-handler?hl=en&authuser=0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.