Skip to content

Fix issue where accounts:lookup is case-sensitive for emails#8351

Merged
joehan merged 1 commit intomasterfrom
aalej-auth-celookup
Mar 21, 2025
Merged

Fix issue where accounts:lookup is case-sensitive for emails#8351
joehan merged 1 commit intomasterfrom
aalej-auth-celookup

Conversation

@aalej
Copy link
Copy Markdown
Contributor

@aalej aalej commented Mar 21, 2025

Description

Fixes #8344

Scenarios Tested

Verified that when connected to the Auth emulator, the 2 code snippets below output the same UserRecord

  1. All lowercase email
const admin = require('firebase-admin');

admin.initializeApp({
    projectId: "demo-project"
})

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"

async function main() {
    try {
        const matchingCase = 'email@example.com';
        const user = await admin.auth().getUserByEmail(matchingCase); // Throws auth/user-not-found
        console.log(user);
    } catch (e) {
        console.error(e); 
    }
}

main()
  1. Random uppercases in email
const admin = require('firebase-admin');

admin.initializeApp({
    projectId: "demo-project"
})

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"

async function main() {
    try {
        const nonMatchingCase = 'EmAiL@eXaMpLe.com';
        const user = await admin.auth().getUserByEmail(nonMatchingCase); // Throws auth/user-not-found
        console.log(user);
    } catch (e) {
        console.error(e); 
    }
}

main()

Sample Commands

Notes

AFAICT, all emails in the emulator are lowercased on signUp

assert(isValidEmailAddress(reqBody.email), "INVALID_EMAIL");
const email = canonicalizeEmailAddress(reqBody.email);
assert(!state.getUserByEmail(email), "EMAIL_EXISTS");
updates.email = email;
. Verified this manually as well.

canonicalizeEmailAddress converts the string to all lower-case

export function canonicalizeEmailAddress(email: string): string {
return email.toLowerCase();
}

@aalej aalej requested a review from joehan March 21, 2025 15:57
Copy link
Copy Markdown
Member

@joehan joehan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joehan joehan merged commit 5264a78 into master Mar 21, 2025
55 checks passed
@joehan joehan deleted the aalej-auth-celookup branch March 21, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

admin.auth().getUserByEmail is case-insensitive against live data, but case-sensitive against emulator data

3 participants