Is there any way to create a user in Firebase using Userame, Email and Password with Golang. A user can be created with Javascript using createUserWithEmailAndPassword(email, password)
But I need the same with Golang. Is there a package or function available? I am using firego to connect with Firebase.
There is no Firebase SDK for Go. But certain parts of Firebase have a REST API that allows you to use those features from almost any platform/technology. The Firebase Database is one of those features and the Firego library is a wrapper around the REST API of the Firebase Database for Go developers.
Unfortunately there is no REST API for creating users in Firebase Authentication. So it won't be possible to create users through Firego or through a public REST API from your Go code.
The simplest solution would be to create a REST endpoint on a app server you control, where you then use the Firebase Admin SDK to create the user.
Recently Google added Go Lang to their list of programming languages that are supported by Firebase Authentication using Firebase Admin SDK.
To create a user:
params := (&auth.UserToCreate{}).
Email("user@example.com").
EmailVerified(false).
PhoneNumber("+1234567890").
Password("secretPassword").
DisplayName("Donald Drump").
PhotoURL("http://www.example.com/12345678/photo.png").
Disabled(false)
u, err := client.CreateUser(context.Background(), params)
if err != nil {
log.Fatalf("error creating user: %v
", err)
}
log.Printf("Successfully created user: %v
", u)
if you want to create a user with your own user ID and don't want an automated generated ID by Firebase then:
params := (&auth.UserToCreate{}).
UID(uid).
Email("user@example.com").
PhoneNumber("+1234567890")
u, err := client.CreateUser(context.Background(), params)
if err != nil {
log.Fatalf("error creating user: %v
", err)
}
log.Printf("User created successfully : %v
", u)
to update a user:
params := (&auth.UserToUpdate{}).
Email("user@example.com").
EmailVerified(true).
PhoneNumber("+1234567890").
Password("newPassword").
DisplayName("Donald Drump").
PhotoURL("http://www.example.com/12345678/photo.png").
Disabled(true)
u, err := client.UpdateUser(context.Background(), uid, params)
if err != nil {
log.Fatalf("error updating user: %v
", err)
}
log.Printf("Successfully updated user: %v
", u)