Skip to content

Commit

Permalink
Add a toJSON() function to auth-exp (#3926)
Browse files Browse the repository at this point in the history
* Add toJSON to auth-exp

* Splitting

* Formatting
  • Loading branch information
sam-gc committed Oct 12, 2020
1 parent cb28261 commit 3c420b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages-exp/auth-exp/src/core/auth/auth_impl.test.ts
Expand Up @@ -454,4 +454,22 @@ describe('core/auth/auth_impl useEmulator', () => {
expect(emulatorEndpoint.calls.length).to.eq(1);
});
});

context('toJSON', () => {
it('works when theres no current user', () => {
expect(JSON.stringify(auth)).to.eq(
'{"apiKey":"test-api-key","authDomain":"localhost","appName":"test-app"}'
);
});

it('also stringifies the current user', () => {
auth.currentUser = ({
toJSON: (): object => ({ foo: 'bar' })
} as unknown) as User;
expect(JSON.stringify(auth)).to.eq(
'{"apiKey":"test-api-key","authDomain":"localhost",' +
'"appName":"test-app","currentUser":{"foo":"bar"}}'
);
});
});
});
9 changes: 9 additions & 0 deletions packages-exp/auth-exp/src/core/auth/auth_impl.ts
Expand Up @@ -247,6 +247,15 @@ export class AuthImpl implements Auth, _FirebaseService {
);
}

toJSON(): object {
return {
apiKey: this.config.apiKey,
authDomain: this.config.authDomain,
appName: this.name,
currentUser: this._currentUser?.toJSON()
};
}

async _setRedirectUser(
user: User | null,
popupRedirectResolver?: externs.PopupRedirectResolver
Expand Down

0 comments on commit 3c420b0

Please sign in to comment.