Thuta Learning
IntermediateDevOps & Toolsintermediate

Signing up with email/password

Relax. We'll talk through this in plain words — no textbook voice.

Signing up with email/password

Once you've enabled the Email/Password provider in Firebase Authentication, you can create a new user account with just a bit of code.

Code Example

javascript
import { getAuth, createUserWithEmailAndPassword } from 'firebase/auth';

const auth = getAuth();

async function signup(email, password) {
  try {
    const userCredential = await createUserWithEmailAndPassword(auth, email, password);
    console.log('New user ID:', userCredential.user.uid);
  } catch (error) {
    console.log('Signup error:', error.code, error.message);
  }
}

signup('student@example.com', 'StrongPass123');

What does this code do?

createUserWithEmailAndPassword sends the email/password to Firebase Auth and creates a new account. On success, you get back userCredential.user.uid. Since the UID is a unique ID for each user, it's crucial for splitting up data by user in your database.

Expected outputNew user ID: abc123UserId

Common mistake

If the password is too weak, you'll get auth/weak-password; if the email format is wrong, auth/invalid-email; if the email is already taken, auth/email-already-in-use. Don't just dump the raw error code on the user — show a friendly, understandable message instead.

Signing up with email/password | Thuta Learning