firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.01k stars 929 forks source link

user reload does not update emailVerified on emulator if emailVerified is updated manually. #6670

Open marcusx2 opened 8 months ago

marcusx2 commented 8 months ago

Operating System

macOS

Browser Version

Safari 16.5.2

Firebase SDK Version

10.7.1

Firebase SDK Product:

Auth

Describe your project's tooling

index.html with source tag. Just javascript.

Describe the problem

emailVerified never returns true when using the emulator after a user.reload and the emailVerified is set to true manually from the console instead of using sendEmailVerification.

I mean to set the emailVerified to true here

image

after creating the user with email and password, instead of sending an email verification with code.

Steps and code to reproduce issue

try {
    const app = initializeApp(firebaseConfig);
    var auth = getAuth();

    connectAuthEmulator(auth, 'http://127.0.0.1:9099');

    var uc = await createUserWithEmailAndPassword(auth, 'bla@bla.com', '123456');
    //at this point, go to emulator console and manually set email to verified
    //instead of sending email verification by code.
    var user = uc.user;
    setInterval(() => {
    if (user?.emailVerified) {
        console.log('email verified');
    } else {
        console.log('email not verified');
        user?.reload();
    }
    }, 0);
} catch (e) {
    console.error(e);
}
marcusx2 commented 8 months ago

One might think this is not a big deal, but I thought user.reload was simply not working on the emulator after I verified that it works without emulator and wasted a lot of time. If this is not considered a big deal at least I'll leave it documented here.

NhienLam commented 8 months ago

Thanks for filing this. Since this issue only happens when using the emulator, I'm going to move this issue to firebase-tools GitHub repository in hopes you can get better support.

joehan commented 8 months ago

Hey @marcusx2, does this issue still occur if you add a call to user = await auth.currentUser();? ie

 if (user?.emailVerified) {
        console.log('email verified');
    } else {
        console.log('email not verified');
        user?.reload();
        user = auth.currentUser()
    }

Based on https://stackoverflow.com/questions/51709733/what-use-case-has-the-reload-function-of-a-firebaseuser-in-flutter, it seems like this is a necessary step.

marcusx2 commented 8 months ago

I didn't try that, but it's not a necessary step without the emulator.