Skip to content

Commit c3f58d4

Browse files
committed
Add toJSON to auth-exp
1 parent 10f038f commit c3f58d4

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
@@ -251,6 +251,15 @@ export class AuthImpl implements Auth, _FirebaseService {
251251
);
252252
}
253253

254+
toJSON(): object {
255+
return {
256+
apiKey: this.config.apiKey,
257+
authDomain: this.config.authDomain,
258+
appName: this.name,
259+
currentUser: this._currentUser?.toJSON()
260+
};
261+
}
262+
254263
async _setRedirectUser(
255264
user: User | null,
256265
popupRedirectResolver?: externs.PopupRedirectResolver

0 commit comments

Comments
 (0)