Skip to content

Commit 3c420b0

Browse files
authored
Add a toJSON() function to auth-exp (#3926)
* Add toJSON to auth-exp * Splitting * Formatting
1 parent cb28261 commit 3c420b0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages-exp/auth-exp/src/core/auth/auth_impl.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,22 @@ describe('core/auth/auth_impl useEmulator', () => {
454454
expect(emulatorEndpoint.calls.length).to.eq(1);
455455
});
456456
});
457+
458+
context('toJSON', () => {
459+
it('works when theres no current user', () => {
460+
expect(JSON.stringify(auth)).to.eq(
461+
'{"apiKey":"test-api-key","authDomain":"localhost","appName":"test-app"}'
462+
);
463+
});
464+
465+
it('also stringifies the current user', () => {
466+
auth.currentUser = ({
467+
toJSON: (): object => ({ foo: 'bar' })
468+
} as unknown) as User;
469+
expect(JSON.stringify(auth)).to.eq(
470+
'{"apiKey":"test-api-key","authDomain":"localhost",' +
471+
'"appName":"test-app","currentUser":{"foo":"bar"}}'
472+
);
473+
});
474+
});
457475
});

packages-exp/auth-exp/src/core/auth/auth_impl.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ export class AuthImpl implements Auth, _FirebaseService {
247247
);
248248
}
249249

250+
toJSON(): object {
251+
return {
252+
apiKey: this.config.apiKey,
253+
authDomain: this.config.authDomain,
254+
appName: this.name,
255+
currentUser: this._currentUser?.toJSON()
256+
};
257+
}
258+
250259
async _setRedirectUser(
251260
user: User | null,
252261
popupRedirectResolver?: externs.PopupRedirectResolver

0 commit comments

Comments
 (0)