考虑到以下限制,我想在我的Vue.js应用中使用Firebase身份验证:
期望的结果将是: a)使用昵称,密码和&注册全名。 b)使用昵称和密码登录
如何使用firebase身份验证对用户进行身份验证?
答案 0 :(得分:1)
<强>注册强>
NickName=nickNameText.getText().toString.trim()+"@firebase.com";
Password = passwordText.getText().toString().trim();
firebaseAuth.createUserWithEmailAndPassword(NickName, Password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//checking if success
if(task.isSuccessful()){
//display some message here
if(type=="User") {
task.getResult().getUser().getUid();
AddUserInfo(task.getResult().getUser().getUid());
}else
{
AddAlimInfo(task.getResult().getUser().getUid());
}
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
intent.putExtra("Type",TypeSpinnerStr);
startActivity(intent);
// startActivity(new Intent(Signup_Activity.this, MainActivity.class));
Toast.makeText(getApplicationContext(),"Successfully registered",Toast.LENGTH_LONG).show();
}else{
//display some message here
Toast.makeText(getApplicationContext(),"Registration Error",Toast.LENGTH_LONG).show();
}
progressDialog.dismiss();
}
});
}
private void AddUserInfo(String id) {
UserClass User=new UserClass();
User.setUserID(id);
User.setUserName(Name);
Email+="@firebase.com";
User.setUserNickname(NickName);
User.setUserPassword(Password);
mdatabaseReference.child("Users").child(UserID).setValue(User);
}
<强>登录强>
private void userLogin(){
nickName= editTextNickName.getText().toString().trim();
password = editTextPassword.getText().toString().trim();
//if the email and password are not empty
//displaying a progress dialog
progressDialog.setMessage("Logging in Please Wait...");
progressDialog.show();
//logging in the user
firebaseAuth.signInWithEmailAndPassword(nickName, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
//if the task is successfull
if(task.isSuccessful()){
//start the profile activity
initFirebase();
//Check in user Node that whether data exists or not
//if exists then login else show Snakbar data does not exist
mAuthUserStr = mAuth.getCurrentUser().getUid();
mEmail=mAuth.getCurrentUser().getEmail();
AddEventFireBaseListner(mAuthUserStr,TypeSpinnerStr);
// startActivity(new Intent(getApplicationContext(), MainActivity.class));
}
}
});
}//end of user
public void AddEventFireBaseListner(String uid,String userType) {
// mdatabaseReference.child("Users").child(UserID).setValue(User);
circular_progress2.setVisibility(View.VISIBLE);
mdatabaseReference.child("Users").child(uid).orderByKey("user_id").equalTo(uid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Compare your Auth Email with user Login email
}
}
答案 1 :(得分:1)
您可以使用custom authentication与Firebase或使用Firebase Admin SDK for node和createUser()功能来执行此操作。
用户的登录流程如下所示:
用户在注册屏幕中输入所需的凭据。
您可以在用户名后将您的域名附加为电子邮件地址,例如您使用用户名为chris注册,然后在您追加@yourdomain.com
的后台,以便它变为chris@yourdomain.com
。这样做会阻止重置密码的选项,因此请记住这一点。