Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/master' into rsgowman/getAccount…
…ByProviderId
  • Loading branch information
rsgowman committed Feb 4, 2021
commit 8dbdd6e9e18eada7d63a6750cd1ec3725c8e208e
2 changes: 1 addition & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ interface GetAccountInfoRequest {
/** Instantiates the getAccountInfo endpoint settings. */
export const FIREBASE_AUTH_GET_ACCOUNT_INFO = new ApiSettings('/accounts:lookup', 'POST')
// Set request validator.
.setRequestValidator((request: any) => {
.setRequestValidator((request: GetAccountInfoRequest) => {
if (!request.localId && !request.email && !request.phoneNumber && !request.federatedUserId) {
throw new FirebaseAuthError(
AuthClientErrorCode.INTERNAL_ERROR,
Expand Down
55 changes: 55 additions & 0 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,61 @@ export class BaseAuth<T extends AbstractAuthRequestHandler> implements BaseAuthI
});
}

/**
* Gets the user data corresponding to the specified identifiers.
*
* There are no ordering guarantees; in particular, the nth entry in the result list is not
* guaranteed to correspond to the nth entry in the input parameters list.
*
* Only a maximum of 100 identifiers may be supplied. If more than 100 identifiers are supplied,
* this method will immediately throw a FirebaseAuthError.
*
* @param identifiers The identifiers used to indicate which user records should be returned. Must
* have <= 100 entries.
* @return {Promise<GetUsersResult>} A promise that resolves to the corresponding user records.
* @throws FirebaseAuthError If any of the identifiers are invalid or if more than 100
* identifiers are specified.
*/
public getUsers(identifiers: UserIdentifier[]): Promise<GetUsersResult> {
if (!validator.isArray(identifiers)) {
throw new FirebaseAuthError(
AuthClientErrorCode.INVALID_ARGUMENT, '`identifiers` parameter must be an array');
}
return this.authRequestHandler
.getAccountInfoByIdentifiers(identifiers)
.then((response: any) => {
/**
* Checks if the specified identifier is within the list of
* UserRecords.
*/
const isUserFound = ((id: UserIdentifier, userRecords: UserRecord[]): boolean => {
return !!userRecords.find((userRecord) => {
if (isUidIdentifier(id)) {
return id.uid === userRecord.uid;
} else if (isEmailIdentifier(id)) {
return id.email === userRecord.email;
} else if (isPhoneIdentifier(id)) {
return id.phoneNumber === userRecord.phoneNumber;
} else if (isProviderIdentifier(id)) {
const matchingUserInfo = userRecord.providerData.find((userInfo) => {
return id.providerId === userInfo.providerId;
});
return !!matchingUserInfo && id.providerUid === matchingUserInfo.uid;
} else {
throw new FirebaseAuthError(
AuthClientErrorCode.INTERNAL_ERROR,
'Unhandled identifier type');
}
});
});

const users = response.users ? response.users.map((user: any) => new UserRecord(user)) : [];
const notFound = identifiers.filter((id) => !isUserFound(id, users));

return { users, notFound };
});
}

/**
* Exports a batch of user accounts. Batch size is determined by the maxResults argument.
* Starting point of the batch is determined by the pageToken argument.
Expand Down
15 changes: 15 additions & 0 deletions src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,21 @@ export namespace auth {
*/
getUserByPhoneNumber(phoneNumber: string): Promise<UserRecord>;

/**
* Gets the user data for the user corresponding to a given provider id.
*
* See [Retrieve user data](/docs/auth/admin/manage-users#retrieve_user_data)
* for code samples and detailed documentation.
*
* @param providerId The provider ID, for example, "google.com" for the
* Google provider.
* @param providerUid The user identifier for the given provider.
*
* @return A promise fulfilled with the user data corresponding to the
* given provider id.
*/
getUserByProviderUid(providerId: string, providerUid: string): Promise<UserRecord>;

/**
* Gets the user data corresponding to the specified identifiers.
*
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.