Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions snippets/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,35 @@ func getUserByPhone(ctx context.Context, client *auth.Client) *auth.UserRecord {
return u
}

func bulkGetUsers(ctx context.Context, client *auth.Client) {
uid := "uid1"
email := "[email protected]"
phone := "+15555551234"
providerID := "google.com"
providerUID := "google_uid1"
// [START bulk_get_users_golang]
getUsersResult, err := client.GetUsers(ctx, []auth.UserIdentifier{
auth.UIDIdentifier{UID: uid},
Copy link
Contributor

Choose a reason for hiding this comment

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

May be inline the values of uid, email etc for clarity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I've also applied this to bulk delete (despite it just being uids.)

auth.EmailIdentifier{Email: email},
auth.PhoneIdentifier{PhoneNumber: phone},
auth.ProviderIdentifier{ProviderID: providerID, ProviderUID: providerUID},
})
if err != nil {
log.Fatalf("error retriving multiple users: %v\n", err)
}

log.Printf("Successfully fetched user data:")
for _, u := range getUsersResult.Users {
log.Printf("%v", u)
}

log.Printf("Unable to find users corresponding to these identifiers:")
for _, id := range getUsersResult.NotFound {
log.Printf("%v", id)
}
// [END bulk_get_users_golang]
}

func createUser(ctx context.Context, client *auth.Client) *auth.UserRecord {
// [START create_user_golang]
params := (&auth.UserToCreate{}).
Expand Down Expand Up @@ -250,6 +279,24 @@ func deleteUser(ctx context.Context, client *auth.Client) {
// [END delete_user_golang]
}

func bulkDeleteUsers(ctx context.Context, client *auth.Client) {
uid1 := "uid1"
uid2 := "uid2"
uid3 := "uid3"
// [START bulk_delete_users_golang]
deleteUsersResult, err := client.DeleteUsers(ctx, []string{uid1, uid2, uid3})
if err != nil {
log.Fatalf("error deleting users: %v\n", err)
}

log.Printf("Successfully deleted %d users", deleteUsersResult.SuccessCount)
log.Printf("Failed to delete %d users", deleteUsersResult.FailureCount)
for _, err := range deleteUsersResult.Errors {
log.Printf("%v", err)
}
// [END bulk_delete_users_golang]
}

func customClaimsSet(ctx context.Context, app *firebase.App) {
uid := "uid"
// [START set_custom_user_claims_golang]
Expand Down