Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
feat: add function to get firebase users
Browse files Browse the repository at this point in the history
  • Loading branch information
mainawycliffe committed Feb 9, 2020
1 parent 2c551f0 commit 1249d21
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
5 changes: 0 additions & 5 deletions firebase/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,3 @@ func DeleteFirebaseUser(ctx context.Context, uid string) error {
}
return nil
}

// ListAllFirebaseUsers get all users in firebase auth
func ListAllFirebaseUsers(ctx context.Context, maxResults uint32, nextPageToken string) error {
panic("not implemented")
}
40 changes: 40 additions & 0 deletions firebase/auth/listUsers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package auth

import (
"context"
"fmt"

"firebase.google.com/go/auth"
"github.com/mainawycliffe/kamanda/firebase"
"google.golang.org/api/iterator"
)

type ListUsersResponse struct {
Users []*auth.ExportedUserRecord
nextPageToken string
}

// ListUsers get all users in firebase auth
func ListUsers(ctx context.Context, maxSize int, nextPageToken string) (ListUsersResponse, error) {
client, err := firebase.Auth(ctx, "")
if err != nil {
return ListUsersResponse{}, fmt.Errorf("Error authenticating firebase account: %w", err)
}
usersIterator := client.Users(ctx, nextPageToken)
users := make([]*auth.ExportedUserRecord, 0)
for {
user, err := usersIterator.Next()
if err == iterator.Done {
break
}
if err != nil {
return ListUsersResponse{}, err
}
users = append(users, user)
}
response := ListUsersResponse{
Users: users,
nextPageToken: usersIterator.PageInfo().Token,
}
return response, nil
}

0 comments on commit 1249d21

Please sign in to comment.