This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to get firebase users
- Loading branch information
1 parent
2c551f0
commit 1249d21
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |