Skip to content

Commit

Permalink
Merge pull request #31 from chemidy/dev
Browse files Browse the repository at this point in the history
add GetUserByPhoneNumber
  • Loading branch information
acoshift committed Aug 7, 2017
2 parents f143ae5 + 14e0bad commit 1637a1d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ This go-firebase-admin SDK supports the following functions :
* GetUsers : fetching list of profile information of users by their uid
* GetUserByEmail : fetching the profile information of users by their email
* GetUsersByEmail : fetching list of profile information of users by their email
* GetUserByPhoneNumber : fetching the profile information of users by their phoneNumber
* GetUsersByPhoneNumber : fetching list of profile information of users by their phoneNumber
* ListUsers : fetching the profile information of users
* CreateUser : create a new Firebase Authentication user
* UpdateUser : modifying an existing Firebase user's data.
Expand Down
4 changes: 4 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type (
EmailVerified bool
// The user's display name.
DisplayName string
// The user's primary phone number.
phoneNumber string
// The user's photo URL.
PhotoURL string
// Whether or not the user is disabled: true for disabled; false for enabled.
Expand Down Expand Up @@ -57,6 +59,8 @@ type (
Email string
// The display name for the linked provider.
DisplayName string
// The phone number for the linked provider.
PhoneNumber string
// The photo URL for the linked provider.
PhotoURL string
// The linked provider ID (for example, "google.com" for the Google provider).
Expand Down
23 changes: 23 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,29 @@ func (auth *Auth) GetUsersByEmail(ctx context.Context, emails []string) ([]*User
return toUserRecords(resp.Users), nil
}

// GetUserByPhoneNumber retrieves user by phoneNumber
func (auth *Auth) GetUserByPhoneNumber(ctx context.Context, phoneNumber string) (*UserRecord, error) {
users, err := auth.GetUsersByPhoneNumber(ctx, []string{phoneNumber})
if err != nil {
return nil, err
}
if len(users) == 0 {
return nil, ErrUserNotFound
}
return users[0], nil
}

// GetUsersByPhoneNumber retrieves users by phoneNumber
func (auth *Auth) GetUsersByPhoneNumber(ctx context.Context, phoneNumber []string) ([]*UserRecord, error) {
resp, err := auth.client.GetAccountInfo(&identitytoolkit.IdentitytoolkitRelyingpartyGetAccountInfoRequest{
PhoneNumber: phoneNumber,
}).Context(ctx).Do()
if err != nil {
return nil, err
}
return toUserRecords(resp.Users), nil
}

// DeleteUser deletes an user by user id
func (auth *Auth) DeleteUser(ctx context.Context, userID string) error {
if len(userID) == 0 {
Expand Down

0 comments on commit 1637a1d

Please sign in to comment.