Skip to content

Commit b147702

Browse files
committed
Update internal types to work with external types
1 parent 12bfc51 commit b147702

File tree

14 files changed

+168
-108
lines changed

14 files changed

+168
-108
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ import { inMemoryPersistence } from '../persistence/in_memory';
3131
import { PersistenceUserManager } from '../persistence/persistence_user_manager';
3232
import { _getClientVersion, ClientPlatform } from '../util/version';
3333
import {
34-
DEFAULT_API_HOST,
35-
DEFAULT_API_SCHEME,
36-
DEFAULT_TOKEN_API_HOST,
37-
initializeAuth
34+
DEFAULT_API_HOST, DEFAULT_API_SCHEME, DEFAULT_TOKEN_API_HOST, initializeAuth
3835
} from './auth_impl';
3936

4037
use(sinonChai);
@@ -138,7 +135,7 @@ describe('core/auth/auth_impl', () => {
138135
const user = testUser('uid');
139136
auth.currentUser = user;
140137
auth._isInitialized = true;
141-
auth.onIdTokenChange(user => {
138+
auth.onIdTokenChanged(user => {
142139
expect(user).to.eq(user);
143140
done();
144141
});
@@ -147,7 +144,7 @@ describe('core/auth/auth_impl', () => {
147144
it('immediate callback is done async', () => {
148145
auth._isInitialized = true;
149146
let callbackCalled = false;
150-
auth.onIdTokenChange(() => {
147+
auth.onIdTokenChanged(() => {
151148
callbackCalled = true;
152149
});
153150

@@ -168,7 +165,7 @@ describe('core/auth/auth_impl', () => {
168165
context('initially currentUser is null', () => {
169166
beforeEach(async () => {
170167
auth.onAuthStateChanged(authStateCallback);
171-
auth.onIdTokenChange(idTokenCallback);
168+
auth.onIdTokenChanged(idTokenCallback);
172169
await auth.updateCurrentUser(null);
173170
authStateCallback.resetHistory();
174171
idTokenCallback.resetHistory();
@@ -188,7 +185,7 @@ describe('core/auth/auth_impl', () => {
188185
context('initially currentUser is user', () => {
189186
beforeEach(async () => {
190187
auth.onAuthStateChanged(authStateCallback);
191-
auth.onIdTokenChange(idTokenCallback);
188+
auth.onIdTokenChanged(idTokenCallback);
192189
await auth.updateCurrentUser(user);
193190
authStateCallback.resetHistory();
194191
idTokenCallback.resetHistory();
@@ -240,8 +237,8 @@ describe('core/auth/auth_impl', () => {
240237
it('onIdTokenChange works for multiple listeners', async () => {
241238
const cb1 = sinon.spy();
242239
const cb2 = sinon.spy();
243-
auth.onIdTokenChange(cb1);
244-
auth.onIdTokenChange(cb2);
240+
auth.onIdTokenChanged(cb1);
241+
auth.onIdTokenChanged(cb2);
245242
await auth.updateCurrentUser(null);
246243
cb1.resetHistory();
247244
cb2.resetHistory();

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@
1717

1818
import { getApp } from '@firebase/app-exp';
1919
import { FirebaseApp } from '@firebase/app-types-exp';
20+
import * as externs from '@firebase/auth-types-exp';
2021
import {
21-
CompleteFn,
22-
createSubscribe,
23-
ErrorFn,
24-
NextFn,
25-
Observer,
26-
Subscribe,
27-
Unsubscribe
22+
CompleteFn, createSubscribe, ErrorFn, NextFn, Observer, Subscribe, Unsubscribe
2823
} from '@firebase/util';
2924

3025
import { Auth, Config, Dependencies, NextOrObserver } from '../../model/auth';
@@ -33,7 +28,7 @@ import { AuthErrorCode } from '../errors';
3328
import { Persistence } from '../persistence';
3429
import { PersistenceUserManager } from '../persistence/persistence_user_manager';
3530
import { assert } from '../util/assert';
36-
import { ClientPlatform, _getClientVersion } from '../util/version';
31+
import { _getClientVersion, ClientPlatform } from '../util/version';
3732

3833
interface AsyncAction {
3934
(): Promise<void>;
@@ -79,6 +74,13 @@ class AuthImpl implements Auth {
7974
this._notifyStateListeners();
8075
});
8176
}
77+
languageCode: string | null = null;
78+
tenantId?: string | null | undefined;
79+
settings: externs.AuthSettings = {appVerificationDisabledForTesting: false};
80+
81+
useDeviceLanguage(): void {
82+
throw new Error("Method not implemented.");
83+
}
8284

8385
updateCurrentUser(user: User | null): Promise<void> {
8486
return this.queue(() => this.directlySetCurrentUser(user));
@@ -107,7 +109,7 @@ class AuthImpl implements Auth {
107109
);
108110
}
109111

110-
onIdTokenChange(
112+
onIdTokenChanged(
111113
nextOrObserver: NextOrObserver<User>,
112114
error?: ErrorFn,
113115
completed?: CompleteFn

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
* limitations under the License.
1616
*/
1717

18-
import {
19-
createAuthUri,
20-
CreateAuthUriRequest
21-
} from '../../api/authentication/create_auth_uri';
18+
import * as externs from '@firebase/auth-types-exp';
19+
20+
import { createAuthUri, CreateAuthUriRequest } from '../../api/authentication/create_auth_uri';
2221
import * as api from '../../api/authentication/email_and_password';
2322
import { Operation } from '../../model/action_code_info';
2423
import {
25-
ActionCodeSettings,
26-
setActionCodeSettingsOnRequest
24+
ActionCodeSettings, setActionCodeSettingsOnRequest
2725
} from '../../model/action_code_settings';
2826
import { Auth } from '../../model/auth';
2927
import { User } from '../../model/user';
3028
import { _getCurrentUrl, _isHttpOrHttps } from '../util/location';
3129

3230
export async function fetchSignInMethodsForEmail(
33-
auth: Auth,
31+
auth: externs.Auth,
3432
email: string
3533
): Promise<string[]> {
3634
// createAuthUri returns an error if continue URI is not http or https.
@@ -42,13 +40,13 @@ export async function fetchSignInMethodsForEmail(
4240
continueUri
4341
};
4442

45-
const { signinMethods } = await createAuthUri(auth, request);
43+
const { signinMethods } = await createAuthUri(auth as Auth, request);
4644

4745
return signinMethods || [];
4846
}
4947

5048
export async function sendEmailVerification(
51-
auth: Auth,
49+
auth: externs.Auth,
5250
user: User,
5351
actionCodeSettings?: ActionCodeSettings
5452
): Promise<void> {
@@ -61,7 +59,7 @@ export async function sendEmailVerification(
6159
setActionCodeSettingsOnRequest(request, actionCodeSettings);
6260
}
6361

64-
const { email } = await api.sendEmailVerification(auth, request);
62+
const { email } = await api.sendEmailVerification(auth as Auth, request);
6563

6664
if (email !== user.email) {
6765
await user.reload();

packages-exp/auth-exp/src/core/strategies/email_and_password.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
* limitations under the License.
1616
*/
1717

18+
import * as externs from '@firebase/auth-types-exp';
19+
1820
import { resetPassword } from '../../api/account_management/email_and_password';
1921
import * as api from '../../api/authentication/email_and_password';
2022
import { ActionCodeInfo, Operation } from '../../model/action_code_info';
2123
import {
22-
ActionCodeSettings,
23-
setActionCodeSettingsOnRequest
24+
ActionCodeSettings, setActionCodeSettingsOnRequest
2425
} from '../../model/action_code_settings';
2526
import { Auth } from '../../model/auth';
26-
import { AuthErrorCode, AUTH_ERROR_FACTORY } from '../errors';
27+
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../errors';
2728

2829
export async function sendPasswordResetEmail(
29-
auth: Auth,
30+
auth: externs.Auth,
3031
email: string,
3132
actionCodeSettings?: ActionCodeSettings
3233
): Promise<void> {
@@ -38,26 +39,26 @@ export async function sendPasswordResetEmail(
3839
setActionCodeSettingsOnRequest(request, actionCodeSettings);
3940
}
4041

41-
await api.sendPasswordResetEmail(auth, request);
42+
await api.sendPasswordResetEmail(auth as Auth, request);
4243
}
4344

4445
export async function confirmPasswordReset(
45-
auth: Auth,
46+
auth: externs.Auth,
4647
oobCode: string,
4748
newPassword: string
4849
): Promise<void> {
49-
await resetPassword(auth, {
50+
await resetPassword(auth as Auth, {
5051
oobCode,
5152
newPassword
5253
});
5354
// Do not return the email.
5455
}
5556

5657
export async function checkActionCode(
57-
auth: Auth,
58+
auth: externs.Auth,
5859
oobCode: string
5960
): Promise<ActionCodeInfo> {
60-
const response = await resetPassword(auth, {
61+
const response = await resetPassword(auth as Auth, {
6162
oobCode
6263
});
6364
if (!response.requestType) {
@@ -76,7 +77,7 @@ export async function checkActionCode(
7677
}
7778

7879
export async function verifyPasswordResetCode(
79-
auth: Auth,
80+
auth: externs.Auth,
8081
code: string
8182
): Promise<string> {
8283
const { data } = await checkActionCode(auth, code);

packages-exp/auth-exp/src/core/strategies/email_link.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
* limitations under the License.
1616
*/
1717

18+
import * as externs from '@firebase/auth-types-exp';
19+
1820
import * as api from '../../api/authentication/email_and_password';
1921
import { Operation } from '../../model/action_code_info';
2022
import {
21-
ActionCodeSettings,
22-
setActionCodeSettingsOnRequest
23+
ActionCodeSettings, setActionCodeSettingsOnRequest
2324
} from '../../model/action_code_settings';
24-
import { ActionCodeURL } from '../action_code_url';
2525
import { Auth } from '../../model/auth';
26+
import { ActionCodeURL } from '../action_code_url';
2627

2728
export async function sendSignInLinkToEmail(
28-
auth: Auth,
29+
auth: externs.Auth,
2930
email: string,
3031
actionCodeSettings?: ActionCodeSettings
3132
): Promise<void> {
@@ -37,10 +38,10 @@ export async function sendSignInLinkToEmail(
3738
setActionCodeSettingsOnRequest(request, actionCodeSettings);
3839
}
3940

40-
await api.sendSignInLinkToEmail(auth, request);
41+
await api.sendSignInLinkToEmail(auth as Auth, request);
4142
}
4243

43-
export function isSignInWithEmailLink(auth: Auth, emailLink: string): boolean {
44-
const actionCodeUrl = ActionCodeURL._fromLink(auth, emailLink);
44+
export function isSignInWithEmailLink(auth: externs.Auth, emailLink: string): boolean {
45+
const actionCodeUrl = ActionCodeURL._fromLink(auth as Auth, emailLink);
4546
return actionCodeUrl?.operation === Operation.EMAIL_SIGNIN;
4647
}

packages-exp/auth-exp/src/core/user/id_token_result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { IdTokenResult, ParsedToken } from '@firebase/auth-types-exp';
1819
import { base64Decode } from '@firebase/util';
1920

20-
import { IdTokenResult, ParsedToken } from '../../model/id_token';
2121
import { User } from '../../model/user';
2222
import { ProviderId } from '../providers';
2323
import { assert } from '../util/assert';

packages-exp/auth-exp/src/core/user/reload.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ import * as chaiAsPromised from 'chai-as-promised';
2020
import * as sinon from 'sinon';
2121
import * as sinonChai from 'sinon-chai';
2222

23+
import { UserInfo } from '@firebase/auth-types-exp';
2324
import { FirebaseError } from '@firebase/util';
2425

2526
import { mockEndpoint } from '../../../test/api/helper';
2627
import { testUser } from '../../../test/mock_auth';
2728
import * as fetch from '../../../test/mock_fetch';
2829
import { Endpoint } from '../../api';
29-
import {
30-
APIUserInfo,
31-
ProviderUserInfo
32-
} from '../../api/account_management/account';
33-
import { UserInfo } from '../../model/user';
30+
import { APIUserInfo, ProviderUserInfo } from '../../api/account_management/account';
3431
import { ProviderId } from '../providers';
3532
import { _reloadWithoutSaving, reload } from './reload';
3633

packages-exp/auth-exp/src/core/user/reload.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
* limitations under the License.
1616
*/
1717

18-
import {
19-
getAccountInfo,
20-
ProviderUserInfo
21-
} from '../../api/account_management/account';
22-
import { User, UserInfo } from '../../model/user';
18+
import * as externs from '@firebase/auth-types-exp';
19+
20+
import { getAccountInfo, ProviderUserInfo } from '../../api/account_management/account';
21+
import { User } from '../../model/user';
2322
import { ProviderId } from '../providers';
2423
import { assert } from '../util/assert';
2524

@@ -52,19 +51,20 @@ export async function _reloadWithoutSaving(user: User): Promise<void> {
5251
Object.assign(user, updates);
5352
}
5453

55-
export async function reload(user: User): Promise<void> {
56-
await _reloadWithoutSaving(user);
54+
export async function reload(user: externs.User): Promise<void> {
55+
const userInternal: User = user as User;
56+
await _reloadWithoutSaving(userInternal);
5757

5858
// Even though the current user hasn't changed, update
5959
// current user will trigger a persistence update w/ the
6060
// new info.
61-
return user.auth.updateCurrentUser(user);
61+
return userInternal.auth.updateCurrentUser(userInternal);
6262
}
6363

6464
function mergeProviderData(
65-
original: UserInfo[],
66-
newData: UserInfo[]
67-
): UserInfo[] {
65+
original: externs.UserInfo[],
66+
newData: externs.UserInfo[]
67+
): externs.UserInfo[] {
6868
const deduped = original.filter(
6969
o => !newData.some(n => n.providerId === o.providerId)
7070
);
@@ -74,7 +74,7 @@ function mergeProviderData(
7474
function extractProviderData(
7575
providers: ProviderUserInfo[],
7676
appName: string
77-
): UserInfo[] {
77+
): externs.UserInfo[] {
7878
return providers.map(({ providerId, ...provider }) => {
7979
assert(
8080
providerId && Object.values<string>(ProviderId).includes(providerId),

packages-exp/auth-exp/src/core/user/user_impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { IdTokenResult } from '@firebase/auth-types-exp';
19+
1820
import { Auth } from '../../model/auth';
19-
import { IdTokenResult } from '../../model/id_token';
2021
import { User } from '../../model/user';
2122
import { PersistedBlob } from '../persistence';
2223
import { ProviderId } from '../providers';
@@ -64,6 +65,7 @@ export class UserImpl implements User {
6465
email: string | null;
6566
phoneNumber: string | null;
6667
photoURL: string | null;
68+
isAnonymous = false;
6769

6870
constructor({ uid, auth, stsTokenManager, ...opt }: UserParameters) {
6971
this.uid = uid;

packages-exp/auth-exp/src/model/auth.d.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18-
import {
19-
CompleteFn,
20-
ErrorFn,
21-
NextFn,
22-
Observer,
23-
Unsubscribe
24-
} from '@firebase/util';
18+
import * as externs from '@firebase/auth-types-exp';
19+
import { CompleteFn, ErrorFn, NextFn, Observer, Unsubscribe } from '@firebase/util';
2520

2621
import { Persistence } from '../core/persistence';
2722
import { User } from './user';
@@ -40,7 +35,7 @@ export interface Config {
4035
authDomain?: AuthDomain;
4136
}
4237

43-
export interface Auth {
38+
export interface Auth extends externs.Auth {
4439
currentUser: User | null;
4540
readonly name: AppName;
4641
readonly config: Config;
@@ -54,7 +49,7 @@ export interface Auth {
5449
error?: ErrorFn,
5550
completed?: CompleteFn
5651
): Unsubscribe;
57-
onIdTokenChange(
52+
onIdTokenChanged(
5853
nextOrObserver: NextOrObserver<User>,
5954
error?: ErrorFn,
6055
completed?: CompleteFn

0 commit comments

Comments
 (0)