Skip to content

Commit c01b7a6

Browse files
committed
Clean up our to/from JSON implementations
- Remove anonymous credential/provider since they're not exposed and don't do anything - rename toPlainObject on User to toJSON per API spec - relax restrictions around ProviderId & SignInMethod typing since they can sometimes have values outside of our enum
1 parent 3ff1898 commit c01b7a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+302
-499
lines changed

packages-exp/auth-compat-exp/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ function registerAuth(instance: _FirebaseNamespace): void {
7070
TwitterAuthProvider: impl.TwitterAuthProvider,
7171
Auth: {
7272
Persistence
73-
}
74-
// 'AuthCredential': fireauth.AuthCredential,
73+
},
74+
AuthCredential: impl.AuthCredential
7575
// 'Error': fireauth.AuthError
7676
})
7777
.setInstantiationMode(InstantiationMode.LAZY)

packages-exp/auth-exp/src/api/account_management/account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export async function deleteAccount(
3636
}
3737

3838
export interface ProviderUserInfo {
39+
providerId: string;
3940
rawId?: string;
40-
providerId?: string;
4141
email?: string;
4242
displayName?: string;
4343
photoUrl?: string;

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import { FirebaseApp } from '@firebase/app-types-exp';
19-
import * as externs from '@firebase/auth-types-exp';
2019
import { FirebaseError } from '@firebase/util';
2120
import { expect, use } from 'chai';
2221
import * as chaiAsPromised from 'chai-as-promised';
@@ -30,6 +29,7 @@ import { _getInstance } from '../util/instantiator';
3029
import * as navigator from '../util/navigator';
3130
import { ClientPlatform } from '../util/version';
3231
import { _castAuth, _initializeAuthForClientPlatform } from './auth_impl';
32+
import { Auth } from '../../model/auth';
3333

3434
use(sinonChai);
3535
use(chaiAsPromised);
@@ -46,14 +46,16 @@ const FAKE_APP: FirebaseApp = {
4646
const initializeAuth = _initializeAuthForClientPlatform(ClientPlatform.BROWSER);
4747

4848
describe('core/auth/auth_impl', () => {
49-
let auth: externs.Auth;
49+
let auth: Auth;
5050
let persistenceStub: sinon.SinonStubbedInstance<Persistence>;
5151

5252
beforeEach(() => {
5353
persistenceStub = sinon.stub(_getInstance(inMemoryPersistence));
54-
auth = initializeAuth(FAKE_APP, {
55-
persistence: inMemoryPersistence
56-
});
54+
auth = _castAuth(
55+
initializeAuth(FAKE_APP, {
56+
persistence: inMemoryPersistence
57+
})
58+
);
5759
});
5860

5961
afterEach(sinon.restore);
@@ -81,7 +83,7 @@ describe('core/auth/auth_impl', () => {
8183
for (let i = 0; i < 10; i++) {
8284
expect(persistenceStub.set.getCall(i)).to.have.been.calledWith(
8385
sinon.match.any,
84-
users[i].toPlainObject()
86+
users[i].toJSON()
8587
);
8688
}
8789
});
@@ -126,28 +128,28 @@ describe('core/auth/auth_impl', () => {
126128

127129
it('immediately calls authStateChange if initialization finished', done => {
128130
const user = testUser(auth, 'uid');
129-
_castAuth(auth).currentUser = user;
130-
_castAuth(auth)._isInitialized = true;
131-
auth.onAuthStateChanged(user => {
131+
auth.currentUser = user;
132+
auth._isInitialized = true;
133+
auth._onAuthStateChanged(user => {
132134
expect(user).to.eq(user);
133135
done();
134136
});
135137
});
136138

137139
it('immediately calls idTokenChange if initialization finished', done => {
138140
const user = testUser(auth, 'uid');
139-
_castAuth(auth).currentUser = user;
140-
_castAuth(auth)._isInitialized = true;
141-
auth.onIdTokenChanged(user => {
141+
auth.currentUser = user;
142+
auth._isInitialized = true;
143+
auth._onIdTokenChanged(user => {
142144
expect(user).to.eq(user);
143145
done();
144146
});
145147
});
146148

147149
it('immediate callback is done async', () => {
148-
_castAuth(auth)._isInitialized = true;
150+
auth._isInitialized = true;
149151
let callbackCalled = false;
150-
auth.onIdTokenChanged(() => {
152+
auth._onIdTokenChanged(() => {
151153
callbackCalled = true;
152154
});
153155

@@ -167,8 +169,8 @@ describe('core/auth/auth_impl', () => {
167169

168170
context('initially currentUser is null', () => {
169171
beforeEach(async () => {
170-
auth.onAuthStateChanged(authStateCallback);
171-
auth.onIdTokenChanged(idTokenCallback);
172+
auth._onAuthStateChanged(authStateCallback);
173+
auth._onIdTokenChanged(idTokenCallback);
172174
await auth.updateCurrentUser(null);
173175
authStateCallback.resetHistory();
174176
idTokenCallback.resetHistory();
@@ -187,8 +189,8 @@ describe('core/auth/auth_impl', () => {
187189

188190
context('initially currentUser is user', () => {
189191
beforeEach(async () => {
190-
auth.onAuthStateChanged(authStateCallback);
191-
auth.onIdTokenChanged(idTokenCallback);
192+
auth._onAuthStateChanged(authStateCallback);
193+
auth._onIdTokenChanged(idTokenCallback);
192194
await auth.updateCurrentUser(user);
193195
authStateCallback.resetHistory();
194196
idTokenCallback.resetHistory();
@@ -226,8 +228,8 @@ describe('core/auth/auth_impl', () => {
226228
it('onAuthStateChange works for multiple listeners', async () => {
227229
const cb1 = sinon.spy();
228230
const cb2 = sinon.spy();
229-
auth.onAuthStateChanged(cb1);
230-
auth.onAuthStateChanged(cb2);
231+
auth._onAuthStateChanged(cb1);
232+
auth._onAuthStateChanged(cb2);
231233
await auth.updateCurrentUser(null);
232234
cb1.resetHistory();
233235
cb2.resetHistory();
@@ -240,8 +242,8 @@ describe('core/auth/auth_impl', () => {
240242
it('onIdTokenChange works for multiple listeners', async () => {
241243
const cb1 = sinon.spy();
242244
const cb2 = sinon.spy();
243-
auth.onIdTokenChanged(cb1);
244-
auth.onIdTokenChanged(cb2);
245+
auth._onIdTokenChanged(cb1);
246+
auth._onIdTokenChanged(cb2);
245247
await auth.updateCurrentUser(null);
246248
cb1.resetHistory();
247249
cb2.resetHistory();

packages-exp/auth-exp/src/core/credentials/anonymous.test.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

packages-exp/auth-exp/src/core/credentials/anonymous.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

packages-exp/auth-exp/src/core/credentials/email.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ import { AuthErrorCode } from '../errors';
2929
import { fail } from '../util/assert';
3030
import { AuthCredential } from './';
3131

32-
export class EmailAuthCredential implements AuthCredential {
33-
readonly providerId = externs.ProviderId.PASSWORD;
34-
32+
export class EmailAuthCredential extends AuthCredential
33+
implements externs.AuthCredential {
3534
private constructor(
3635
readonly email: string,
3736
readonly password: string,
38-
readonly signInMethod: externs.SignInMethod
39-
) {}
37+
signInMethod: externs.SignInMethod
38+
) {
39+
super(externs.ProviderId.PASSWORD, signInMethod);
40+
}
4041

4142
static _fromEmailAndPassword(
4243
email: string,

packages-exp/auth-exp/src/core/credentials/index.d.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)