Google Firebase 忘记密码
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]
}
这里link给你指导:
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 重置,您首先需要向用户发送电子邮件,为此我们使用 sendPasswordResetEmail 方法。之后,如果用户要点击电子邮件,它将被重定向到 firebase 提供的默认页面,用户可以从那里重置密码。
但是,如果您想要自定义密码重置页面,您也可以这样做,为此您需要在您的 firebase 项目的电子邮件模板中更改操作 url,然后您需要设置该自定义操作 url,为此您可以阅读此官方文档页面:https://firebase.google.com/docs/auth/custom-email-handler?hl=en&authuser=0
你是如何在我的方法中实现忘记密码的方法。我正在创建一个即将到期的 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]
}
这里link给你指导: 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 重置,您首先需要向用户发送电子邮件,为此我们使用 sendPasswordResetEmail 方法。之后,如果用户要点击电子邮件,它将被重定向到 firebase 提供的默认页面,用户可以从那里重置密码。
但是,如果您想要自定义密码重置页面,您也可以这样做,为此您需要在您的 firebase 项目的电子邮件模板中更改操作 url,然后您需要设置该自定义操作 url,为此您可以阅读此官方文档页面:https://firebase.google.com/docs/auth/custom-email-handler?hl=en&authuser=0