アプリで_Java-script
_ _fire-base
_を使用しています。
アプリでcreateUserWithEmailAndPassword
を正常に処理できます。また、_Fire-base Console
_内のデータを示しています。
これがスニペットです。
_firebase.auth().createUserWithEmailAndPassword("[email protected]", "*******").catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log("Eroor Msg" + errorMessage);
// ...
});
_
次に、firebase.auth().signInWithEmailAndPassword
を実行しました。
上記の方法では、log
への成功イベントまたはメッセージを取得できません。 error
も投げていません。
これがスニペットです。
_firebase.auth().signInWithEmailAndPassword("[email protected]", "*****")
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
});
_
私の質問は、このメソッドsignInWithEmailAndPassword
で成功イベントを取得する方法です。
どんな助けも大歓迎です。
以下のコードを確認してください:
firebase.auth().signInWithEmailAndPassword("[email protected]", "******")
.then(function(firebaseUser) {
// Success
})
.catch(function(error) {
// Error Handling
});
これはonAuthStateオブジェクトを使用して実行する必要があります。以下は、ユーザーが正常にログインしたかどうかを確認するコードです。
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});
サインインに成功すると、このコードを実行できます。ところで、SignInWithEmailAndPasswordが検証するオブジェクトを返すことはありません。
戻りイベントで「関数」を使用するタイミングを人々に理解させるために、他のコードに少し批判的になることはできますか...
//run one function only
.then(function(firebaseUser) => this.myfunction(firebaseUser); );
//run lines of code
.then((firebaseUser) => {
// line1
// line2
);
Ionicの私のコードは、AngularCLIの場合は少し異なる場合があります
public async dologinUser(newEmail: string, newPassword: string): Promise<any> {
try {
return await this._afAuth.auth.signInWithEmailAndPassword(newEmail, newPassword)
.then((firebaseUser) => {
if (firebaseUser) {
//do something
}
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
alert(errorMessage);
});
} catch (e) {
console.error("big hu?", e);
}
}