0
0
Firebasecloud~5 mins

Email/password login in Firebase - Commands & Configuration

Choose your learning style9 modes available
Introduction
Email/password login lets users sign into your app using their email and a secret password. It solves the problem of identifying users securely without needing social media or other accounts.
When you want users to create accounts with just an email and password.
When you need a simple way to authenticate users without external providers.
When you want to manage user access and permissions based on their login.
When you want to allow password resets and email verification easily.
When you want to keep user data safe with Firebase's secure authentication.
Config File - firebase.json
firebase.json
{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "/api/**",
        "function": "api"
      }
    ]
  },
  "auth": {
    "signInOptions": [
      {
        "provider": "password"
      }
    ]
  }
}

This file configures Firebase Hosting and enables email/password sign-in under the auth.signInOptions section. The password provider allows users to register and login with email and password.

Commands
Log in to your Firebase account from the command line to allow deployment and management.
Terminal
firebase login
Expected OutputExpected
✔ Success! Logged in as user@example.com
Initialize Firebase Authentication in your project to enable email/password login.
Terminal
firebase init auth
Expected OutputExpected
✔ Firebase Authentication has been set up in your project. ✔ Email/password sign-in method enabled.
Deploy the authentication configuration to Firebase so email/password login is active.
Terminal
firebase deploy --only auth
Expected OutputExpected
=== Deploying to 'your-project-id'... ✔ Deploy complete! Project Console: https://console.firebase.google.com/project/your-project-id/overview
--only - Deploy only the specified Firebase feature, here 'auth' for authentication.
Sign in a user with their email and password to test the login functionality.
Terminal
firebase auth:signInWithEmailAndPassword user@example.com mySecurePass123
Expected OutputExpected
{ "uid": "some-unique-user-id", "email": "user@example.com", "emailVerified": false, "isAnonymous": false }
Key Concept

If you remember nothing else from this pattern, remember: email/password login lets users securely access your app with just their email and a secret password managed by Firebase.

Common Mistakes
Not enabling the email/password sign-in method in Firebase console or config.
Users cannot log in because Firebase rejects email/password authentication if not enabled.
Always enable the email/password provider in Firebase Authentication settings before deploying.
Using weak or common passwords during user registration.
Weak passwords increase risk of account compromise and reduce security.
Enforce strong password rules in your app and educate users to choose secure passwords.
Not handling errors from sign-in commands, like wrong password or unregistered email.
Your app may crash or behave unpredictably without proper error handling.
Always check and handle authentication errors gracefully in your app code.
Summary
Use 'firebase login' to authenticate your CLI with Firebase.
Initialize authentication with 'firebase init auth' to enable email/password login.
Deploy your auth settings using 'firebase deploy --only auth'.
Test user login with 'firebase auth:signInWithEmailAndPassword email password'.