Skip to content

Commit 4c449aa

Browse files
committed
Snippets for bulk get/delete function
Corresponding doc change to enable it: http://cl/282953279
1 parent f26af19 commit 4c449aa

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

snippets/auth.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,35 @@ func getUserByPhone(ctx context.Context, client *auth.Client) *auth.UserRecord {
185185
return u
186186
}
187187

188+
func bulkGetUsers(ctx context.Context, client *auth.Client) {
189+
uid := "uid1"
190+
email := "[email protected]"
191+
phone := "+15555551234"
192+
providerID := "google.com"
193+
providerUID := "google_uid1"
194+
// [START bulk_get_users_golang]
195+
getUsersResult, err := client.GetUsers(ctx, []auth.UserIdentifier{
196+
auth.UIDIdentifier{UID: uid},
197+
auth.EmailIdentifier{Email: email},
198+
auth.PhoneIdentifier{PhoneNumber: phone},
199+
auth.ProviderIdentifier{ProviderID: providerID, ProviderUID: providerUID},
200+
})
201+
if err != nil {
202+
log.Fatalf("error retriving multiple users: %v\n", err)
203+
}
204+
205+
log.Printf("Successfully fetched user data:")
206+
for _, u := range getUsersResult.Users {
207+
log.Printf("%v", u)
208+
}
209+
210+
log.Printf("Unable to find users corresponding to these identifiers:")
211+
for _, id := range getUsersResult.NotFound {
212+
log.Printf("%v", id)
213+
}
214+
// [END bulk_get_users_golang]
215+
}
216+
188217
func createUser(ctx context.Context, client *auth.Client) *auth.UserRecord {
189218
// [START create_user_golang]
190219
params := (&auth.UserToCreate{}).
@@ -250,6 +279,24 @@ func deleteUser(ctx context.Context, client *auth.Client) {
250279
// [END delete_user_golang]
251280
}
252281

282+
func bulkDeleteUsers(ctx context.Context, client *auth.Client) {
283+
uid1 := "uid1"
284+
uid2 := "uid2"
285+
uid3 := "uid3"
286+
// [START bulk_delete_users_golang]
287+
deleteUsersResult, err := client.DeleteUsers(ctx, []string{uid1, uid2, uid3})
288+
if err != nil {
289+
log.Fatalf("error deleting users: %v\n", err)
290+
}
291+
292+
log.Printf("Successfully deleted %d users", deleteUsersResult.SuccessCount)
293+
log.Printf("Failed to delete %d users", deleteUsersResult.FailureCount)
294+
for _, err := range deleteUsersResult.Errors {
295+
log.Printf("%v", err)
296+
}
297+
// [END bulk_delete_users_golang]
298+
}
299+
253300
func customClaimsSet(ctx context.Context, app *firebase.App) {
254301
uid := "uid"
255302
// [START set_custom_user_claims_golang]

0 commit comments

Comments
 (0)