I'd like to use Firebase for my web app that is for people with dementia in a care home. They do not have email or social network accounts so will need a simple username / password sign up / sign in.
What is the easiest way to do this? From what I can see in the docs I'd have to use a custom auth flow but I do not have an existing auth server.
If I do need ot do this what is the easiest way to provide the token? In Azure there is Functions and AWS has Lambda but I see nothing here is Firebase
If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() . signOut() .
You create a new user in your Firebase project by calling the createUserWithEmailAndPassword method or by signing in a user for the first time using a federated identity provider, such as Google Sign-In or Facebook Login.
Firebase account linking allows users to sign into the same account using different authentication providers. By linking the user's Facebook and Twitter credentials, for example, the user can sign into the same account using either sign-in provider.
You are correct that username/password sign-in is not supported natively in Firebase Auth at this moment.
You can implement a custom provider as shown in this example. This allows you to meet any custom requirements, but is admittedly a bit more involved than using the built-in providers. There is an example of this here that you can use as a starting point.
A workaround you could take without needing to use custom auth with another backend is to accept usernames in your UI, but on the underlying logic, append "@yourowndomain.com" before calling the functions to sign up or sign in with email.
So you would be using email/password authentication, mapping <username> to <username>@yourowndomain.com
Appending a dummy domain at end is a kind of a patch up and should be avoided. To enable username login just follow these simple steps.
Sign Up
During sign up take the userid , email and password . Register the user with normal email and password. On Success of it save the email against the user_id in a separate node(branch).
mButtonSignUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(isValid()){ mProgressBar.setVisibility(View.VISIBLE); final String userId = mEditTextUserId.getText().toString(); final String emailId = mEditTextEmail.getText().toString() ; String password = mEditTextPassword.getText().toString() ; firebaseRef.createUser(emailId, password, new Firebase.ResultHandler() { @Override public void onSuccess() { firebaseRef.child("user_ids").child(userId).setValue(emailId); Toast.makeText(getBaseContext(),"You are successfully registered ",Toast.LENGTH_SHORT).show(); mProgressBar.setVisibility(View.GONE); } @Override public void onError(FirebaseError firebaseError) { mProgressBar.setVisibility(View.GONE); Toast.makeText(getBaseContext(),firebaseError.toString(),Toast.LENGTH_SHORT).show(); } }); } } }); Database
Database structure will look like this

Login
Check if the user has entered an email or userId. If it is a email id then directly perform login with it otherwise fetch the email id associated with the username and perform login.
Button buttonLogIn = (Button)findViewById(R.id.button_login); buttonLogIn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mProgressBar.setVisibility(View.VISIBLE); String username = mEditTextEmail.getText().toString() ; final String password = mEditTextPassWord.getText().toString() ; // Check if it is an email or not if(android.util.Patterns.EMAIL_ADDRESS.matcher(username).matches()) { performLogin(username,password); }else{ //get the emailId associated with the username firebaseRef.child("user_ids").child(username) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot!=null){ String userEmail = dataSnapshot.getValue(String.class); performLogin(userEmail,password); } } @Override public void onCancelled(FirebaseError firebaseError) { //Handle Error } }); } } }); private void performLogin(String emailId, String password) { firebaseRef.authWithPassword(emailId,password, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { uid = authData.getUid() ; Toast.makeText(getBaseContext(), authData.toString(), Toast.LENGTH_SHORT).show(); } @Override public void onAuthenticationError(FirebaseError firebaseError) { Toast.makeText(getBaseContext(), firebaseError.toString(), Toast.LENGTH_SHORT).show(); } }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With