firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.12k stars 239 forks source link

auth.Client.CreateUser(...) panics if email is already in use in project #486

Closed StainlessStlRat closed 2 years ago

StainlessStlRat commented 2 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

Attempt to create a user whose email is already in use with the project configured for only one account per email

Relevant Code:

// RegisterUser register a user with firebase
func RegisterUser(email string, password string, handle string) (UID string, err error) {
    params := (&auth.UserToCreate{}).
        Email(email).
        EmailVerified(false).
        Password(password).
        DisplayName(handle).
        Disabled(false)
    userRecord, err := authClient.CreateUser(context.Background(), params)
    return userRecord.UID, err
}
lahirumaramba commented 2 years ago

I think it panics because you try to access UID in a null userRecord. You can handle the errors as below:

userRecord, err := authClient.CreateUser(context.Background(), params)
if err != nil {
    log.Fatalln("Error when registering user: ", err)
}
return userRecord.UID