Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,10 +1152,14 @@ export abstract class AbstractAuthRequestHandler {
}

public getAccountInfoByFederatedUid(providerId: string, rawId: string): Promise<object> {
if (!validator.isNonEmptyString(providerId) || !validator.isNonEmptyString(rawId)) {
if (!validator.isNonEmptyString(providerId)) {
throw new FirebaseAuthError(AuthClientErrorCode.INVALID_PROVIDER_ID);
}

if (!validator.isNonEmptyString(rawId)) {
throw new FirebaseAuthError(AuthClientErrorCode.INVALID_UID);
}
Comment on lines +1159 to +1161

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly throws a more specific INVALID_UID error for an empty rawId, aligning with validateProviderUserInfo as mentioned in the pull request description. However, there seems to be another inconsistency in the codebase. The addProviderToRequest function (line 1051) throws AuthClientErrorCode.INVALID_PROVIDER_UID for an empty providerUid. This function is used by getUsers().

This means auth.getUserByProviderUid('a', '') will throw auth/invalid-uid, while auth.getUsers([{providerId: 'a', providerUid: ''}]) will throw auth/invalid-provider-uid.

While fixing this might be outside the scope of this PR, it would be good to create a follow-up issue to make these error codes consistent across the API for a better developer experience.


const request = {
federatedUserId: [{
providerId,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/auth/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,10 +1397,10 @@ AUTH_CONFIGS.forEach((testConfig) => {
.with.property('code', 'auth/invalid-provider-id');
});

it('should be rejected given an invalid provider uid', () => {
it('should be rejected given an invalid uid', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test description was changed from "should be rejected given an invalid provider uid" to "should be rejected given an invalid uid". The former is more descriptive and less ambiguous, as "uid" could be misinterpreted as the Firebase user UID, whereas this test is specifically for the provider-specific UID. I suggest reverting to the more specific description to improve test clarity.

Suggested change
it('should be rejected given an invalid uid', () => {
it('should be rejected given an invalid provider uid', () => {

expect(() => auth.getUserByProviderUid('id', ''))
.to.throw(FirebaseAuthError)
.with.property('code', 'auth/invalid-provider-id');
.with.property('code', 'auth/invalid-uid');
});

it('should be rejected given an app which returns null access tokens', () => {
Expand Down