Skip to content

Commit c401d96

Browse files
authored
fix(auth): Fixing UserImportRecord typings declaration (#835)
* fix(auth): Fixing UserImportRecord typings declaration * Fixing more integration test compilation errors * Trigger CI * Removed redundant line
1 parent 013582a commit c401d96

File tree

3 files changed

+93
-28
lines changed

3 files changed

+93
-28
lines changed

docgen/content-sources/node/toc.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ toc:
8686
path: /docs/reference/admin/node/admin.auth.UserInfo
8787
- title: "UserMetadata"
8888
path: /docs/reference/admin/node/admin.auth.UserMetadata
89+
- title: "UserMetadataRequest"
90+
path: /docs/reference/admin/node/admin.auth.UserMetadataRequest
91+
- title: "UserProviderRequest"
92+
path: /docs/reference/admin/node/admin.auth.UserProviderRequest
8993
- title: "UserRecord"
9094
path: /docs/reference/admin/node/admin.auth.UserRecord
9195
- title: "SessionCookieOptions"

src/auth.d.ts

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,58 @@ export namespace admin.auth {
624624
errors: _admin.FirebaseArrayIndexError[];
625625
}
626626

627+
/**
628+
* User metadata to include when importing a user.
629+
*/
630+
interface UserMetadataRequest {
631+
632+
/**
633+
* The date the user last signed in, formatted as a UTC string.
634+
*/
635+
lastSignInTime?: string;
636+
637+
/**
638+
* The date the user was created, formatted as a UTC string.
639+
*/
640+
creationTime?: string;
641+
}
642+
643+
/**
644+
* User provider data to include when importing a user.
645+
*/
646+
interface UserProviderRequest {
647+
648+
/**
649+
* The user identifier for the linked provider.
650+
*/
651+
uid: string;
652+
653+
/**
654+
* The display name for the linked provider.
655+
*/
656+
displayName?: string;
657+
658+
/**
659+
* The email for the linked provider.
660+
*/
661+
email?: string;
662+
663+
/**
664+
* The phone number for the linked provider.
665+
*/
666+
phoneNumber?: string;
667+
668+
/**
669+
* The photo URL for the linked provider.
670+
*/
671+
photoURL?: string;
672+
673+
/**
674+
* The linked provider ID (for example, "google.com" for the Google provider).
675+
*/
676+
providerId: string;
677+
}
678+
627679
/**
628680
* Interface representing a user to import to Firebase Auth via the
629681
* {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#importUsers `importUsers()`} method.
@@ -643,7 +695,7 @@ export namespace admin.auth {
643695
/**
644696
* Whether or not the user's primary email is verified.
645697
*/
646-
emailVerified: boolean;
698+
emailVerified?: boolean;
647699

648700
/**
649701
* The user's display name.
@@ -664,17 +716,17 @@ export namespace admin.auth {
664716
* Whether or not the user is disabled: `true` for disabled; `false` for
665717
* enabled.
666718
*/
667-
disabled: boolean;
719+
disabled?: boolean;
668720

669721
/**
670722
* Additional metadata about the user.
671723
*/
672-
metadata: admin.auth.UserMetadata;
724+
metadata?: admin.auth.UserMetadataRequest;
673725

674726
/**
675727
* An array of providers (for example, Google, Facebook) linked to the user.
676728
*/
677-
providerData?: admin.auth.UserInfo[];
729+
providerData?: admin.auth.UserProviderRequest[];
678730

679731
/**
680732
* The user's custom claims object if available, typically used to define
@@ -703,6 +755,11 @@ export namespace admin.auth {
703755
* to the tenant corresponding to that `TenantAwareAuth` instance's tenant ID.
704756
*/
705757
tenantId?: string | null;
758+
759+
/**
760+
* The user's multi-factor related properties.
761+
*/
762+
multiFactor?: admin.auth.MultiFactorUpdateSettings;
706763
}
707764

708765
/**

test/integration/auth.spec.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ describe('admin.auth', () => {
14211421

14221422
describe('importUsers()', () => {
14231423
const randomUid = 'import_' + generateRandomString(20).toLowerCase();
1424-
let importUserRecord: any;
1424+
let importUserRecord: admin.auth.UserImportRecord;
14251425
const rawPassword = 'password';
14261426
const rawSalt = 'NaCl';
14271427
// Simulate a user stored using SCRYPT being migrated to Firebase Auth via importUsers.
@@ -1635,15 +1635,15 @@ describe('admin.auth', () => {
16351635
return admin.auth().getUser(uid);
16361636
}).then((userRecord) => {
16371637
// The phone number provider will be appended to the list of accounts.
1638-
importUserRecord.providerData.push({
1639-
uid: importUserRecord.phoneNumber,
1638+
importUserRecord.providerData?.push({
1639+
uid: importUserRecord.phoneNumber!,
16401640
providerId: 'phone',
1641-
phoneNumber: importUserRecord.phoneNumber,
1641+
phoneNumber: importUserRecord.phoneNumber!,
16421642
});
16431643
const actualUserRecord: {[key: string]: any} = userRecord.toJSON();
16441644
for (const key of Object.keys(importUserRecord)) {
16451645
expect(JSON.stringify(actualUserRecord[key]))
1646-
.to.be.equal(JSON.stringify(importUserRecord[key]));
1646+
.to.be.equal(JSON.stringify((importUserRecord as any)[key]));
16471647
}
16481648
}).should.eventually.be.fulfilled;
16491649
});
@@ -1652,6 +1652,23 @@ describe('admin.auth', () => {
16521652
const uid = generateRandomString(20).toLowerCase();
16531653
const email = uid + '@example.com';
16541654
const now = new Date(1476235905000).toUTCString();
1655+
const enrolledFactors: admin.auth.UpdatePhoneMultiFactorInfoRequest[] = [
1656+
{
1657+
uid: 'mfaUid1',
1658+
phoneNumber: '+16505550001',
1659+
displayName: 'Work phone number',
1660+
factorId: 'phone',
1661+
enrollmentTime: now,
1662+
} ,
1663+
{
1664+
uid: 'mfaUid2',
1665+
phoneNumber: '+16505550002',
1666+
displayName: 'Personal phone number',
1667+
factorId: 'phone',
1668+
enrollmentTime: now,
1669+
},
1670+
];
1671+
16551672
importUserRecord = {
16561673
uid,
16571674
email,
@@ -1671,22 +1688,7 @@ describe('admin.auth', () => {
16711688
},
16721689
],
16731690
multiFactor: {
1674-
enrolledFactors: [
1675-
{
1676-
uid: 'mfaUid1',
1677-
phoneNumber: '+16505550001',
1678-
displayName: 'Work phone number',
1679-
factorId: 'phone',
1680-
enrollmentTime: now,
1681-
},
1682-
{
1683-
uid: 'mfaUid2',
1684-
phoneNumber: '+16505550002',
1685-
displayName: 'Personal phone number',
1686-
factorId: 'phone',
1687-
enrollmentTime: now,
1688-
},
1689-
],
1691+
enrolledFactors,
16901692
},
16911693
};
16921694
uids.push(importUserRecord.uid);
@@ -1702,7 +1704,7 @@ describe('admin.auth', () => {
17021704
const actualUserRecord: {[key: string]: any} = userRecord.toJSON();
17031705
expect(actualUserRecord.multiFactor.enrolledFactors.length).to.equal(2);
17041706
expect(actualUserRecord.multiFactor.enrolledFactors)
1705-
.to.deep.equal(importUserRecord.multiFactor.enrolledFactors);
1707+
.to.deep.equal(importUserRecord.multiFactor?.enrolledFactors);
17061708
}).should.eventually.be.fulfilled;
17071709
});
17081710

@@ -1741,7 +1743,9 @@ describe('admin.auth', () => {
17411743
* @retunr {Promise<void>} A promise that resolved on success.
17421744
*/
17431745
function testImportAndSignInUser(
1744-
importUserRecord: any, importOptions: any, rawPassword: string): Promise<void> {
1746+
importUserRecord: admin.auth.UserImportRecord,
1747+
importOptions: any,
1748+
rawPassword: string): Promise<void> {
17451749
const users = [importUserRecord];
17461750
// Import the user record.
17471751
return admin.auth().importUsers(users, importOptions)
@@ -1751,7 +1755,7 @@ function testImportAndSignInUser(
17511755
expect(result.successCount).to.equal(1);
17521756
expect(result.errors.length).to.equal(0);
17531757
// Sign in with an email and password to the imported account.
1754-
return clientAuth().signInWithEmailAndPassword(users[0].email, rawPassword);
1758+
return clientAuth().signInWithEmailAndPassword(users[0].email!, rawPassword);
17551759
})
17561760
.then(({user}) => {
17571761
// Confirm successful sign-in.

0 commit comments

Comments
 (0)