Skip to content

Commit 5d91f76

Browse files
committed
Cleanup public types in auth-next (#3217)
* Cleanup public types in auth-next * PR feedback
1 parent fa2b37c commit 5d91f76

23 files changed

+390
-237
lines changed

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

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

18+
import { Operation } from '@firebase/auth-types-exp';
19+
1820
import { Endpoint, HttpMethod, _performApiRequest } from '..';
19-
import { Operation } from '../../model/action_code_info';
2021
import { Auth } from '../../model/auth';
2122
import { IdTokenResponse } from '../../model/id_token';
2223

packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { Endpoint } from '../';
2424
import { mockEndpoint } from '../../../test/api/helper';
2525
import { testAuth } from '../../../test/mock_auth';
2626
import * as mockFetch from '../../../test/mock_fetch';
27-
import { Operation } from '../../model/action_code_info';
2827
import { Auth } from '../../model/auth';
2928
import { ServerError } from '../errors';
3029
import {
@@ -36,6 +35,7 @@ import {
3635
signInWithPassword,
3736
VerifyEmailRequest
3837
} from './email_and_password';
38+
import { Operation } from '@firebase/auth-types-exp';
3939

4040
use(chaiAsPromised);
4141

packages-exp/auth-exp/src/api/authentication/email_and_password.ts

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

18+
import { Operation } from '@firebase/auth-types-exp';
19+
1820
import {
1921
Endpoint,
2022
HttpMethod,
@@ -23,7 +25,6 @@ import {
2325
} from '..';
2426
import { Auth } from '../../model/auth';
2527
import { IdToken, IdTokenResponse } from '../../model/id_token';
26-
import { Operation } from '../../model/action_code_info';
2728

2829
export interface SignInWithPasswordRequest {
2930
returnSecureToken?: boolean;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
import { expect } from 'chai';
1919

20+
import { Operation } from '@firebase/auth-types-exp';
21+
2022
import { testAuth } from '../../test/mock_auth';
21-
import { Operation } from '../model/action_code_info';
2223
import { Auth } from '../model/auth';
2324
import { ActionCodeURL } from './action_code_url';
2425

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import * as externs from '@firebase/auth-types-exp';
1919

20-
import { Operation } from '../model/action_code_info';
2120
import { Auth } from '../model/auth';
2221
import { AUTH_ERROR_FACTORY, AuthErrorCode } from './errors';
2322

@@ -37,19 +36,19 @@ enum QueryField {
3736
/**
3837
* Map from mode string in action code URL to Action Code Info operation.
3938
*/
40-
const MODE_TO_OPERATION_MAP: { [key: string]: Operation } = {
41-
'recoverEmail': Operation.RECOVER_EMAIL,
42-
'resetPassword': Operation.PASSWORD_RESET,
43-
'signIn': Operation.EMAIL_SIGNIN,
44-
'verifyEmail': Operation.VERIFY_EMAIL,
45-
'verifyAndChangeEmail': Operation.VERIFY_AND_CHANGE_EMAIL,
46-
'revertSecondFactorAddition': Operation.REVERT_SECOND_FACTOR_ADDITION
39+
const MODE_TO_OPERATION_MAP: { [key: string]: externs.Operation } = {
40+
'recoverEmail': externs.Operation.RECOVER_EMAIL,
41+
'resetPassword': externs.Operation.PASSWORD_RESET,
42+
'signIn': externs.Operation.EMAIL_SIGNIN,
43+
'verifyEmail': externs.Operation.VERIFY_EMAIL,
44+
'verifyAndChangeEmail': externs.Operation.VERIFY_AND_CHANGE_EMAIL,
45+
'revertSecondFactorAddition': externs.Operation.REVERT_SECOND_FACTOR_ADDITION
4746
};
4847

4948
/**
5049
* Maps the mode string in action code URL to Action Code Info operation.
5150
*/
52-
function parseMode(mode: string | null): Operation | null {
51+
function parseMode(mode: string | null): externs.Operation | null {
5352
return mode ? MODE_TO_OPERATION_MAP[mode] || null : null;
5453
}
5554

@@ -71,7 +70,7 @@ export class ActionCodeURL implements externs.ActionCodeURL {
7170
readonly code: string;
7271
readonly continueUrl: string | null;
7372
readonly languageCode: string | null;
74-
readonly operation: Operation;
73+
readonly operation: externs.Operation;
7574
readonly tenantId: string | null;
7675

7776
constructor(auth: Auth, actionLink: string) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
Unsubscribe
2929
} from '@firebase/util';
3030

31-
import { Auth, Dependencies, NextOrObserver } from '../../model/auth';
31+
import { Auth, Dependencies } from '../../model/auth';
3232
import { User } from '../../model/user';
3333
import { AuthErrorCode } from '../errors';
3434
import { Persistence } from '../persistence';
@@ -57,7 +57,7 @@ export class AuthImpl implements Auth {
5757
private lastNotifiedUid: string | undefined = undefined;
5858

5959
languageCode: string | null = null;
60-
tenantId?: string | null | undefined;
60+
tenantId: string | null = null;
6161
settings: externs.AuthSettings = { appVerificationDisabledForTesting: false };
6262

6363
constructor(
@@ -107,7 +107,7 @@ export class AuthImpl implements Auth {
107107
}
108108

109109
onAuthStateChanged(
110-
nextOrObserver: NextOrObserver<User>,
110+
nextOrObserver: externs.NextOrObserver<User>,
111111
error?: ErrorFn,
112112
completed?: CompleteFn
113113
): Unsubscribe {
@@ -120,7 +120,7 @@ export class AuthImpl implements Auth {
120120
}
121121

122122
onIdTokenChanged(
123-
nextOrObserver: NextOrObserver<User>,
123+
nextOrObserver: externs.NextOrObserver<User>,
124124
error?: ErrorFn,
125125
completed?: CompleteFn
126126
): Unsubscribe {
@@ -160,7 +160,7 @@ export class AuthImpl implements Auth {
160160

161161
private registerStateListener(
162162
subscription: Subscription<User>,
163-
nextOrObserver: NextOrObserver<User>,
163+
nextOrObserver: externs.NextOrObserver<User>,
164164
error?: ErrorFn,
165165
completed?: CompleteFn
166166
): Unsubscribe {

packages-exp/auth-exp/src/core/providers/phone.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { initializeAuth } from '../auth/auth_impl';
2424
import { PhoneAuthCredential } from '../credentials/phone';
2525
import { _verifyPhoneNumber } from '../strategies/phone';
2626
import { debugFail } from '../util/assert';
27+
import { ApplicationVerifier } from '../../model/application_verifier';
2728

2829
export class PhoneAuthProvider implements externs.PhoneAuthProvider {
2930
static readonly PROVIDER_ID = externs.ProviderId.PHONE;
@@ -37,11 +38,14 @@ export class PhoneAuthProvider implements externs.PhoneAuthProvider {
3738
}
3839

3940
verifyPhoneNumber(
40-
phoneNumber: string,
41+
phoneOptions: externs.PhoneInfoOptions | string,
4142
applicationVerifier: externs.ApplicationVerifier
42-
/* multiFactorSession?: MultiFactorSession, */
4343
): Promise<string> {
44-
return _verifyPhoneNumber(this.auth, phoneNumber, applicationVerifier);
44+
return _verifyPhoneNumber(
45+
this.auth,
46+
phoneOptions,
47+
applicationVerifier as ApplicationVerifier
48+
);
4549
}
4650

4751
static credential(

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ import * as chaiAsPromised from 'chai-as-promised';
2020
import { restore, SinonStub, stub } from 'sinon';
2121
import * as sinonChai from 'sinon-chai';
2222

23-
import { ProviderId } from '@firebase/auth-types-exp';
23+
import { ProviderId, Operation } from '@firebase/auth-types-exp';
2424
import { FirebaseError } from '@firebase/util';
2525

2626
import { mockEndpoint } from '../../../test/api/helper';
2727
import { testAuth, testUser } from '../../../test/mock_auth';
2828
import * as mockFetch from '../../../test/mock_fetch';
2929
import { Endpoint } from '../../api';
3030
import { ServerError } from '../../api/errors';
31-
import { Operation } from '../../model/action_code_info';
3231
import { Auth } from '../../model/auth';
3332
import { User } from '../../model/user';
3433
import * as location from '../util/location';
@@ -134,7 +133,7 @@ describe('core/strategies/sendEmailVerification', () => {
134133
email
135134
});
136135

137-
await sendEmailVerification(auth, user);
136+
await sendEmailVerification(user);
138137

139138
expect(reloadStub).to.not.have.been.called;
140139
expect(mock.calls[0].request).to.eql({
@@ -149,7 +148,7 @@ describe('core/strategies/sendEmailVerification', () => {
149148
150149
});
151150

152-
await sendEmailVerification(auth, user);
151+
await sendEmailVerification(user);
153152

154153
expect(reloadStub).to.have.been.calledOnce;
155154
expect(mock.calls[0].request).to.eql({
@@ -164,7 +163,7 @@ describe('core/strategies/sendEmailVerification', () => {
164163
requestType: Operation.VERIFY_EMAIL,
165164
email
166165
});
167-
await sendEmailVerification(auth, user, {
166+
await sendEmailVerification(user, {
168167
handleCodeInApp: true,
169168
iOS: {
170169
bundleId: 'my-bundle',
@@ -192,7 +191,7 @@ describe('core/strategies/sendEmailVerification', () => {
192191
requestType: Operation.VERIFY_EMAIL,
193192
email
194193
});
195-
await sendEmailVerification(auth, user, {
194+
await sendEmailVerification(user, {
196195
handleCodeInApp: true,
197196
android: {
198197
installApp: false,

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
*/
1717

1818
import * as externs from '@firebase/auth-types-exp';
19-
import { ActionCodeSettings } from '@firebase/auth-types-exp';
2019

2120
import {
2221
createAuthUri,
2322
CreateAuthUriRequest
2423
} from '../../api/authentication/create_auth_uri';
2524
import * as api from '../../api/authentication/email_and_password';
26-
import { Operation } from '../../model/action_code_info';
2725
import { Auth } from '../../model/auth';
2826
import { User } from '../../model/user';
2927
import { _getCurrentUrl, _isHttpOrHttps } from '../util/location';
@@ -48,20 +46,20 @@ export async function fetchSignInMethodsForEmail(
4846
}
4947

5048
export async function sendEmailVerification(
51-
auth: externs.Auth,
52-
user: User,
53-
actionCodeSettings?: ActionCodeSettings
49+
userExtern: externs.User,
50+
actionCodeSettings?: externs.ActionCodeSettings | null
5451
): Promise<void> {
52+
const user = userExtern as User;
5553
const idToken = await user.getIdToken();
5654
const request: api.VerifyEmailRequest = {
57-
requestType: Operation.VERIFY_EMAIL,
55+
requestType: externs.Operation.VERIFY_EMAIL,
5856
idToken
5957
};
6058
if (actionCodeSettings) {
6159
setActionCodeSettingsOnRequest(request, actionCodeSettings);
6260
}
6361

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import {
19+
Operation,
1920
OperationType,
2021
ProviderId,
2122
SignInMethod
@@ -30,7 +31,6 @@ import * as mockFetch from '../../../test/mock_fetch';
3031
import { Endpoint } from '../../api';
3132
import { APIUserInfo } from '../../api/account_management/account';
3233
import { ServerError } from '../../api/errors';
33-
import { Operation } from '../../model/action_code_info';
3434
import { Auth } from '../../model/auth';
3535
import {
3636
checkActionCode,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as externs from '@firebase/auth-types-exp';
1919

2020
import { resetPassword } from '../../api/account_management/email_and_password';
2121
import * as api from '../../api/authentication/email_and_password';
22-
import { Operation } from '../../model/action_code_info';
2322
import { Auth } from '../../model/auth';
2423
import { AuthErrorCode, AUTH_ERROR_FACTORY } from '../errors';
2524
import { EmailAuthProvider } from '../providers/email';
@@ -34,7 +33,7 @@ export async function sendPasswordResetEmail(
3433
actionCodeSettings?: externs.ActionCodeSettings
3534
): Promise<void> {
3635
const request: api.PasswordResetRequest = {
37-
requestType: Operation.PASSWORD_RESET,
36+
requestType: externs.Operation.PASSWORD_RESET,
3837
email
3938
};
4039
if (actionCodeSettings) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import { expect, use } from 'chai';
1919
import * as chaiAsPromised from 'chai-as-promised';
2020
import * as sinonChai from 'sinon-chai';
2121

22+
import * as externs from '@firebase/auth-types-exp';
2223
import { FirebaseError } from '@firebase/util';
2324

2425
import { mockEndpoint } from '../../../test/api/helper';
2526
import { testAuth } from '../../../test/mock_auth';
2627
import * as mockFetch from '../../../test/mock_fetch';
2728
import { Endpoint } from '../../api';
2829
import { ServerError } from '../../api/errors';
29-
import { Operation } from '../../model/action_code_info';
3030
import { Auth } from '../../model/auth';
3131
import {
3232
isSignInWithEmailLink,
@@ -61,7 +61,7 @@ describe('core/strategies/sendSignInLinkToEmail', () => {
6161
});
6262
await sendSignInLinkToEmail(auth, email);
6363
expect(mock.calls[0].request).to.eql({
64-
requestType: Operation.EMAIL_SIGNIN,
64+
requestType: externs.Operation.EMAIL_SIGNIN,
6565
email
6666
});
6767
});
@@ -100,7 +100,7 @@ describe('core/strategies/sendSignInLinkToEmail', () => {
100100
});
101101

102102
expect(mock.calls[0].request).to.eql({
103-
requestType: Operation.EMAIL_SIGNIN,
103+
requestType: externs.Operation.EMAIL_SIGNIN,
104104
email,
105105
continueUrl: 'my-url',
106106
dynamicLinkDomain: 'fdl-domain',
@@ -127,7 +127,7 @@ describe('core/strategies/sendSignInLinkToEmail', () => {
127127
dynamicLinkDomain: 'fdl-domain'
128128
});
129129
expect(mock.calls[0].request).to.eql({
130-
requestType: Operation.EMAIL_SIGNIN,
130+
requestType: externs.Operation.EMAIL_SIGNIN,
131131
email,
132132
continueUrl: 'my-url',
133133
dynamicLinkDomain: 'fdl-domain',

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import * as externs from '@firebase/auth-types-exp';
1919

2020
import * as api from '../../api/authentication/email_and_password';
21-
import { Operation } from '../../model/action_code_info';
2221
import { Auth } from '../../model/auth';
2322
import { ActionCodeURL } from '../action_code_url';
2423
import { EmailAuthProvider } from '../providers/email';
@@ -32,7 +31,7 @@ export async function sendSignInLinkToEmail(
3231
actionCodeSettings?: externs.ActionCodeSettings
3332
): Promise<void> {
3433
const request: api.EmailSignInRequest = {
35-
requestType: Operation.EMAIL_SIGNIN,
34+
requestType: externs.Operation.EMAIL_SIGNIN,
3635
email
3736
};
3837
if (actionCodeSettings) {
@@ -47,7 +46,7 @@ export function isSignInWithEmailLink(
4746
emailLink: string
4847
): boolean {
4948
const actionCodeUrl = ActionCodeURL._fromLink(auth as Auth, emailLink);
50-
return actionCodeUrl?.operation === Operation.EMAIL_SIGNIN;
49+
return actionCodeUrl?.operation === externs.Operation.EMAIL_SIGNIN;
5150
}
5251

5352
export async function signInWithEmailLink(

0 commit comments

Comments
 (0)