Я создаю приложение Angular и использую проверку подлинности электронной почты Firebase.
Это работало отлично, пока я не начал использовать ссылку электронной почты для подтверждения учетной записи.
После регистрации я создаю пользователя и затем отправляю ему ссылку для входа на его почту.
Я попробовал это, я зарегистрировался, получил ссылку, нажал на нее, и он вошел в систему все в порядке.
Однако, как только я выйду из системы, это не даст мне войти в систему с моим паролем, сказав The password is invalid or the user does not have a password.
Мне нужно сбросить пароль и только тогда он работает.
Это мой код:
signup(email: string, password: string, firstname: string, lastname, nickname: string, address: string) {
this.firebaseAuth
.auth
.createUserWithEmailAndPassword(email, password)
.then(value => {
this.u = value.user;
this.u.updateProfile({ displayName: nickname, photoURL: null });
this.firebaseAuth.auth.updateCurrentUser(this.u);
var actionCodeSettings = {
// URL you want to redirect back to. The domain (www.example.com) for this
// URL must be whitelisted in the Firebase Console.
//url: 'http://localhost:4200/finishSignUp',
url: 'https://mybay-990af.firebaseapp.com/finishSignUp',
// This must be true.
handleCodeInApp: true,
};
this.firebaseAuth.auth.sendSignInLinkToEmail(email, actionCodeSettings)
.then(function () {
// The link was successfully sent. Inform the user.
// Save the email locally so you don't need to ask the user for it again
// if they open the link on the same device.
window.localStorage.setItem('emailForSignIn', email);
})
.catch(function (error) {
// Some error occurred, you can inspect the code: error.code
});
console.log('Success!', value);
})
.catch(err => {
console.log('Something went wrong:', err.message);
});
}
loginWithEmailLink() {
// Confirm the link is a sign-in with email link.
if (this.firebaseAuth
.auth.isSignInWithEmailLink(window.location.href)) {
// Additional state parameters can also be passed via URL.
// This can be used to continue the user's intended action before triggering
// the sign-in operation.
// Get the email if available. This should be available if the user completes
// the flow on the same device where they started it.
var email = window.localStorage.getItem('emailForSignIn');
if (!email) {
// User opened the link on a different device. To prevent session fixation
// attacks, ask the user to provide the associated email again. For example:
email = window.prompt('Please provide your email for confirmation');
}
// The client SDK will parse the code from the link for you.
this.firebaseAuth
.auth.signInWithEmailLink(email, window.location.href)
.then((result) => {
// Clear email from storage.
window.localStorage.removeItem('emailForSignIn');
// You can access the new user via result.user
// Additional user info profile not available via:
// result.additionalUserInfo.profile == null
// You can check if the user is new or existing:
// result.additionalUserInfo.isNewUser
this.u = result.user;
this.sendPaymentMethod(email).then(sent => {
this.router.navigate(['/store'])
});
})
.catch(function (error) {
console.log(error);
// Some error occurred, you can inspect the code: error.code
// Common errors could be invalid email and invalid or expired OTPs.
});
}
}
login(email: string, password: string) {
var signed = this.firebaseAuth
.auth
.signInWithEmailAndPassword(email, password)
.then(value => {
return true;
})
.catch(err => {
console.log(err);
return err.message;
});
return signed;
}
Есть идеи, что не так?