Skip to content

Commit 12e7465

Browse files
committed
Update internal types to work with external types (#3075)
* Update internal types to work with external types * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * PR feedback * [AUTOMATED]: Prettier Code Styling
1 parent 9b26963 commit 12e7465

File tree

15 files changed

+163
-75
lines changed

15 files changed

+163
-75
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('core/auth/auth_impl', () => {
138138
const user = testUser('uid');
139139
auth.currentUser = user;
140140
auth._isInitialized = true;
141-
auth.onIdTokenChange(user => {
141+
auth.onIdTokenChanged(user => {
142142
expect(user).to.eq(user);
143143
done();
144144
});
@@ -147,7 +147,7 @@ describe('core/auth/auth_impl', () => {
147147
it('immediate callback is done async', () => {
148148
auth._isInitialized = true;
149149
let callbackCalled = false;
150-
auth.onIdTokenChange(() => {
150+
auth.onIdTokenChanged(() => {
151151
callbackCalled = true;
152152
});
153153

@@ -168,7 +168,7 @@ describe('core/auth/auth_impl', () => {
168168
context('initially currentUser is null', () => {
169169
beforeEach(async () => {
170170
auth.onAuthStateChanged(authStateCallback);
171-
auth.onIdTokenChange(idTokenCallback);
171+
auth.onIdTokenChanged(idTokenCallback);
172172
await auth.updateCurrentUser(null);
173173
authStateCallback.resetHistory();
174174
idTokenCallback.resetHistory();
@@ -188,7 +188,7 @@ describe('core/auth/auth_impl', () => {
188188
context('initially currentUser is user', () => {
189189
beforeEach(async () => {
190190
auth.onAuthStateChanged(authStateCallback);
191-
auth.onIdTokenChange(idTokenCallback);
191+
auth.onIdTokenChanged(idTokenCallback);
192192
await auth.updateCurrentUser(user);
193193
authStateCallback.resetHistory();
194194
idTokenCallback.resetHistory();
@@ -240,8 +240,8 @@ describe('core/auth/auth_impl', () => {
240240
it('onIdTokenChange works for multiple listeners', async () => {
241241
const cb1 = sinon.spy();
242242
const cb2 = sinon.spy();
243-
auth.onIdTokenChange(cb1);
244-
auth.onIdTokenChange(cb2);
243+
auth.onIdTokenChanged(cb1);
244+
auth.onIdTokenChanged(cb2);
245245
await auth.updateCurrentUser(null);
246246
cb1.resetHistory();
247247
cb2.resetHistory();

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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 {
2122
CompleteFn,
2223
createSubscribe,
@@ -33,7 +34,7 @@ import { AuthErrorCode } from '../errors';
3334
import { Persistence } from '../persistence';
3435
import { PersistenceUserManager } from '../persistence/persistence_user_manager';
3536
import { assert } from '../util/assert';
36-
import { ClientPlatform, _getClientVersion } from '../util/version';
37+
import { _getClientVersion, ClientPlatform } from '../util/version';
3738

3839
interface AsyncAction {
3940
(): Promise<void>;
@@ -79,6 +80,13 @@ class AuthImpl implements Auth {
7980
this._notifyStateListeners();
8081
});
8182
}
83+
languageCode: string | null = null;
84+
tenantId?: string | null | undefined;
85+
settings: externs.AuthSettings = { appVerificationDisabledForTesting: false };
86+
87+
useDeviceLanguage(): void {
88+
throw new Error('Method not implemented.');
89+
}
8290

8391
updateCurrentUser(user: User | null): Promise<void> {
8492
return this.queue(() => this.directlySetCurrentUser(user));
@@ -107,7 +115,7 @@ class AuthImpl implements Auth {
107115
);
108116
}
109117

110-
onIdTokenChange(
118+
onIdTokenChanged(
111119
nextOrObserver: NextOrObserver<User>,
112120
error?: ErrorFn,
113121
completed?: CompleteFn

packages-exp/auth-exp/src/core/persistence/react_native.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2019 Google Inc.
3+
* Copyright 2019 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import {
2121
PersistenceValue,
2222
STORAGE_AVAILABLE_KEY
2323
} from './';
24-
import {ReactNativeAsyncStorage} from '@firebase/auth-types-exp';
24+
import { ReactNativeAsyncStorage } from '@firebase/auth-types-exp';
2525

2626
/**
2727
* Persistence class that wraps AsyncStorage imported from `react-native` or `@react-native-community/async-storage`.
@@ -48,9 +48,7 @@ export class ReactNativePersistence implements Persistence {
4848
await this.storage.setItem(key, JSON.stringify(value));
4949
}
5050

51-
async get<T extends PersistenceValue>(
52-
key: string
53-
): Promise<T | null> {
51+
async get<T extends PersistenceValue>(key: string): Promise<T | null> {
5452
const json = await this.storage.getItem(key);
5553
return json ? JSON.parse(json) : null;
5654
}

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

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

18+
import * as externs from '@firebase/auth-types-exp';
19+
1820
import {
1921
createAuthUri,
2022
CreateAuthUriRequest
@@ -30,7 +32,7 @@ import { User } from '../../model/user';
3032
import { _getCurrentUrl, _isHttpOrHttps } from '../util/location';
3133

3234
export async function fetchSignInMethodsForEmail(
33-
auth: Auth,
35+
auth: externs.Auth,
3436
email: string
3537
): Promise<string[]> {
3638
// createAuthUri returns an error if continue URI is not http or https.
@@ -42,13 +44,13 @@ export async function fetchSignInMethodsForEmail(
4244
continueUri
4345
};
4446

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

4749
return signinMethods || [];
4850
}
4951

5052
export async function sendEmailVerification(
51-
auth: Auth,
53+
auth: externs.Auth,
5254
user: User,
5355
actionCodeSettings?: ActionCodeSettings
5456
): Promise<void> {
@@ -61,7 +63,7 @@ export async function sendEmailVerification(
6163
setActionCodeSettingsOnRequest(request, actionCodeSettings);
6264
}
6365

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

6668
if (email !== user.email) {
6769
await user.reload();

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
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';
@@ -23,10 +25,10 @@ import {
2325
setActionCodeSettingsOnRequest
2426
} from '../../model/action_code_settings';
2527
import { Auth } from '../../model/auth';
26-
import { AuthErrorCode, AUTH_ERROR_FACTORY } from '../errors';
28+
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../errors';
2729

2830
export async function sendPasswordResetEmail(
29-
auth: Auth,
31+
auth: externs.Auth,
3032
email: string,
3133
actionCodeSettings?: ActionCodeSettings
3234
): Promise<void> {
@@ -38,26 +40,26 @@ export async function sendPasswordResetEmail(
3840
setActionCodeSettingsOnRequest(request, actionCodeSettings);
3941
}
4042

41-
await api.sendPasswordResetEmail(auth, request);
43+
await api.sendPasswordResetEmail(auth as Auth, request);
4244
}
4345

4446
export async function confirmPasswordReset(
45-
auth: Auth,
47+
auth: externs.Auth,
4648
oobCode: string,
4749
newPassword: string
4850
): Promise<void> {
49-
await resetPassword(auth, {
51+
await resetPassword(auth as Auth, {
5052
oobCode,
5153
newPassword
5254
});
5355
// Do not return the email.
5456
}
5557

5658
export async function checkActionCode(
57-
auth: Auth,
59+
auth: externs.Auth,
5860
oobCode: string
5961
): Promise<ActionCodeInfo> {
60-
const response = await resetPassword(auth, {
62+
const response = await resetPassword(auth as Auth, {
6163
oobCode
6264
});
6365
if (!response.requestType) {
@@ -76,7 +78,7 @@ export async function checkActionCode(
7678
}
7779

7880
export async function verifyPasswordResetCode(
79-
auth: Auth,
81+
auth: externs.Auth,
8082
code: string
8183
): Promise<string> {
8284
const { data } = await checkActionCode(auth, code);

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
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 {
2123
ActionCodeSettings,
2224
setActionCodeSettingsOnRequest
2325
} from '../../model/action_code_settings';
24-
import { ActionCodeURL } from '../action_code_url';
2526
import { Auth } from '../../model/auth';
27+
import { ActionCodeURL } from '../action_code_url';
2628

2729
export async function sendSignInLinkToEmail(
28-
auth: Auth,
30+
auth: externs.Auth,
2931
email: string,
3032
actionCodeSettings?: ActionCodeSettings
3133
): Promise<void> {
@@ -37,10 +39,13 @@ export async function sendSignInLinkToEmail(
3739
setActionCodeSettingsOnRequest(request, actionCodeSettings);
3840
}
3941

40-
await api.sendSignInLinkToEmail(auth, request);
42+
await api.sendSignInLinkToEmail(auth as Auth, request);
4143
}
4244

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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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';
@@ -30,7 +31,6 @@ import {
3031
APIUserInfo,
3132
ProviderUserInfo
3233
} from '../../api/account_management/account';
33-
import { UserInfo } from '../../model/user';
3434
import { ProviderId } from '../providers';
3535
import { _reloadWithoutSaving, reload } from './reload';
3636

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

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

18+
import * as externs from '@firebase/auth-types-exp';
19+
1820
import {
1921
getAccountInfo,
2022
ProviderUserInfo
2123
} from '../../api/account_management/account';
22-
import { User, UserInfo } from '../../model/user';
24+
import { User } from '../../model/user';
2325
import { ProviderId } from '../providers';
2426
import { assert } from '../util/assert';
2527

@@ -52,7 +54,8 @@ export async function _reloadWithoutSaving(user: User): Promise<void> {
5254
Object.assign(user, updates);
5355
}
5456

55-
export async function reload(user: User): Promise<void> {
57+
export async function reload(externUser: externs.User): Promise<void> {
58+
const user: User = externUser as User;
5659
await _reloadWithoutSaving(user);
5760

5861
// Even though the current user hasn't changed, update
@@ -62,9 +65,9 @@ export async function reload(user: User): Promise<void> {
6265
}
6366

6467
function mergeProviderData(
65-
original: UserInfo[],
66-
newData: UserInfo[]
67-
): UserInfo[] {
68+
original: externs.UserInfo[],
69+
newData: externs.UserInfo[]
70+
): externs.UserInfo[] {
6871
const deduped = original.filter(
6972
o => !newData.some(n => n.providerId === o.providerId)
7073
);
@@ -74,7 +77,7 @@ function mergeProviderData(
7477
function extractProviderData(
7578
providers: ProviderUserInfo[],
7679
appName: string
77-
): UserInfo[] {
80+
): externs.UserInfo[] {
7881
return providers.map(({ providerId, ...provider }) => {
7982
assert(
8083
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
import * as externs from '@firebase/auth-types-exp';
1819
import {
1920
CompleteFn,
2021
ErrorFn,
@@ -40,7 +41,7 @@ export interface Config {
4041
authDomain?: AuthDomain;
4142
}
4243

43-
export interface Auth {
44+
export interface Auth extends externs.Auth {
4445
currentUser: User | null;
4546
readonly name: AppName;
4647
readonly config: Config;
@@ -54,7 +55,7 @@ export interface Auth {
5455
error?: ErrorFn,
5556
completed?: CompleteFn
5657
): Unsubscribe;
57-
onIdTokenChange(
58+
onIdTokenChanged(
5859
nextOrObserver: NextOrObserver<User>,
5960
error?: ErrorFn,
6061
completed?: CompleteFn

0 commit comments

Comments
 (0)