Skip to content

fix(auth): Fixing some public API signatures to be consistent with the current API #1221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2021
Merged
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
4 changes: 2 additions & 2 deletions etc/firebase-admin.auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export abstract class MultiFactorInfo {
// @public
export class MultiFactorSettings {
enrolledFactors: MultiFactorInfo[];
toJSON(): any;
toJSON(): object;
}

// @public
Expand Down Expand Up @@ -394,7 +394,7 @@ export class UserInfo {
// @public
export class UserMetadata {
readonly creationTime: string;
readonly lastRefreshTime: string | null;
readonly lastRefreshTime?: string | null;
readonly lastSignInTime: string;
toJSON(): object;
}
Expand Down
5 changes: 3 additions & 2 deletions src/auth/user-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface GetAccountInfoUserResponse {
mfaInfo?: MultiFactorInfoResponse[];
createdAt?: string;
lastLoginAt?: string;
lastRefreshAt?: string;
[key: string]: any;
}

Expand Down Expand Up @@ -277,7 +278,7 @@ export class MultiFactorSettings {
/**
* @return A JSON-serializable representation of this multi-factor object.
*/
public toJSON(): any {
public toJSON(): object {
return {
enrolledFactors: this.enrolledFactors.map((info) => info.toJSON()),
};
Expand All @@ -304,7 +305,7 @@ export class UserMetadata {
* formatted as a UTC Date string (eg 'Sat, 03 Feb 2001 04:05:06 GMT').
* Returns null if the user was never active.
*/
public readonly lastRefreshTime: string | null;
public readonly lastRefreshTime?: string | null;

/**
* @param response The server side response returned from the getAccountInfo
Expand Down
9 changes: 9 additions & 0 deletions test/unit/auth/user-record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,15 @@ describe('UserMetadata', () => {
it('should return expected lastRefreshTime', () => {
expect(actualMetadata.lastRefreshTime).to.equal(new Date(expectedLastRefreshAt).toUTCString())
});

it('should return null when lastRefreshTime is not available', () => {
const metadata: UserMetadata = new UserMetadata({
localId: 'uid123',
lastLoginAt: expectedLastLoginAt.toString(),
createdAt: expectedCreatedAt.toString(),
});
expect(metadata.lastRefreshTime).to.be.null;
});
});

describe('toJSON', () => {
Expand Down