Skip to content

Commit 075778a

Browse files
committed
Add toJSON to auth-exp
1 parent cb28261 commit 075778a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,4 +454,15 @@ 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('{"apiKey":"test-api-key","authDomain":"localhost","appName":"test-app"}');
461+
});
462+
463+
it('also stringifies the current user', () => {
464+
auth.currentUser = {toJSON: (): object => ({foo: 'bar'})} as unknown as User;
465+
expect(JSON.stringify(auth)).to.eq('{"apiKey":"test-api-key","authDomain":"localhost","appName":"test-app","currentUser":{"foo":"bar"}}');
466+
});
467+
});
457468
});

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)