Skip to content

Commit 9162f00

Browse files
committed
PR feedback
1 parent 7d74696 commit 9162f00

File tree

13 files changed

+105
-67
lines changed

13 files changed

+105
-67
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ use(chaiAsPromised);
3030

3131
describe('core/credentials/anonymous', () => {
3232
let auth: Auth;
33-
const credential = new AnonymousCredential();
33+
let credential: AnonymousCredential;
3434

3535
beforeEach(async () => {
3636
auth = await testAuth();
37+
credential = new AnonymousCredential();
3738
});
3839

3940
it('should have an anonymous provider', () => {
@@ -85,9 +86,9 @@ describe('core/credentials/anonymous', () => {
8586

8687
describe('#_matchIdTokenWithUid', () => {
8788
it('throws', () => {
88-
expect(() =>
89-
credential._matchIdTokenWithUid(auth, 'other-uid')
90-
).to.throw(Error);
89+
expect(() => credential._matchIdTokenWithUid(auth, 'other-uid')).to.throw(
90+
Error
91+
);
9192
});
9293
});
93-
});
94+
});

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

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

18-
import {
19-
ProviderId,
20-
SignInMethod
21-
} from '@firebase/auth-types-exp';
18+
import { ProviderId, SignInMethod } from '@firebase/auth-types-exp';
2219
import { signUp } from '../../api/authentication/sign_up';
2320
import { Auth } from '../../model/auth';
2421
import { IdTokenResponse } from '../../model/id_token';

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ describe('core/credentials/email', () => {
4141
});
4242

4343
context('email & password', () => {
44-
const credential = new EmailAuthCredential('some-email', 'some-password', EmailAuthProvider.PROVIDER_ID, EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD);
44+
const credential = new EmailAuthCredential(
45+
'some-email',
46+
'some-password',
47+
EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD
48+
);
4549

4650
beforeEach(() => {
4751
mockFetch.setUp();
@@ -101,7 +105,11 @@ describe('core/credentials/email', () => {
101105
});
102106

103107
context('email link', () => {
104-
const credential = new EmailAuthCredential('some-email', 'oob-code', EmailAuthProvider.PROVIDER_ID, EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD);
108+
const credential = new EmailAuthCredential(
109+
'some-email',
110+
'oob-code',
111+
EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD
112+
);
105113

106114
beforeEach(() => {
107115
mockFetch.setUp();
@@ -158,4 +166,4 @@ describe('core/credentials/email', () => {
158166
});
159167
});
160168
});
161-
});
169+
});

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import { debugFail } from '../util/assert';
2626
import { AuthCredential } from '.';
2727

2828
export class EmailAuthCredential implements AuthCredential {
29+
readonly providerId = EmailAuthProvider.PROVIDER_ID;
30+
2931
constructor(
3032
readonly email: string,
3133
readonly password: string,
32-
readonly providerId: typeof EmailAuthProvider.PROVIDER_ID,
3334
readonly signInMethod: externs.SignInMethod
3435
) {}
3536

@@ -42,7 +43,7 @@ export class EmailAuthCredential implements AuthCredential {
4243
}
4344

4445
async _getIdTokenResponse(auth: Auth): Promise<IdTokenResponse> {
45-
switch (this.signInMethod) {
46+
switch (this.signInMethod) {
4647
case EmailAuthProvider.EMAIL_PASSWORD_SIGN_IN_METHOD:
4748
return signInWithPassword(auth, {
4849
returnSecureToken: true,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Auth } from '../../model/auth';
2222

2323
export abstract class AuthCredential extends externs.AuthCredential {
2424
static fromJSON(json: object | string): AuthCredential | null;
25-
25+
2626
_getIdTokenResponse(auth: Auth): Promise<PhoneOrOauthTokenResponse>;
2727
_linkToIdToken(auth: Auth, idToken: string): Promise<IdTokenResponse>;
2828
_matchIdTokenWithUid(auth: Auth, uid: string): Promise<IdTokenResponse>;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export interface PhoneAuthCredentialParameters {
3434
temporaryProof?: string;
3535
}
3636

37-
export class PhoneAuthCredential implements AuthCredential, externs.PhoneAuthCredential {
37+
export class PhoneAuthCredential
38+
implements AuthCredential, externs.PhoneAuthCredential {
3839
readonly providerId = externs.ProviderId.PHONE;
3940
readonly signInMethod = externs.SignInMethod.PHONE;
4041

@@ -120,4 +121,4 @@ export class PhoneAuthCredential implements AuthCredential, externs.PhoneAuthCre
120121
temporaryProof
121122
});
122123
}
123-
}
124+
}

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ describe('core/providers/email', () => {
3535

3636
describe('.credential', () => {
3737
it('should return an email & password credential', () => {
38-
const credential = EmailAuthProvider.credential('some-email', 'some-password');
38+
const credential = EmailAuthProvider.credential(
39+
'some-email',
40+
'some-password'
41+
);
3942
expect(credential.email).to.eq('some-email');
4043
expect(credential.password).to.eq('some-password');
4144
expect(credential.providerId).to.eq(ProviderId.PASSWORD);
@@ -53,7 +56,11 @@ describe('core/providers/email', () => {
5356
encodeURIComponent(continueUrl) +
5457
'&languageCode=en&state=bla';
5558

56-
const credential = EmailAuthProvider.credentialWithLink(auth, 'some-email', actionLink);
59+
const credential = EmailAuthProvider.credentialWithLink(
60+
auth,
61+
'some-email',
62+
actionLink
63+
);
5764
expect(credential.email).to.eq('some-email');
5865
expect(credential.password).to.eq('CODE');
5966
expect(credential.providerId).to.eq(ProviderId.PASSWORD);
@@ -87,4 +94,4 @@ describe('core/providers/email', () => {
8794
});
8895
});
8996
});
90-
});
97+
});

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import * as externs from '@firebase/auth-types-exp';
2020
import { Auth } from '../../model/auth';
2121
import { ActionCodeURL } from '../action_code_url';
2222
import { EmailAuthCredential } from '../credentials/email';
23-
import { AuthErrorCode, AUTH_ERROR_FACTORY } from '../errors';
23+
import { AuthErrorCode } from '../errors';
24+
import { assert } from '../util/assert';
2425

2526
export class EmailAuthProvider implements externs.EmailAuthProvider {
2627
static readonly PROVIDER_ID = externs.ProviderId.PASSWORD;
2728
static readonly EMAIL_PASSWORD_SIGN_IN_METHOD =
2829
externs.SignInMethod.EMAIL_PASSWORD;
2930
static readonly EMAIL_LINK_SIGN_IN_METHOD = externs.SignInMethod.EMAIL_LINK;
30-
readonly providerId: externs.ProviderId = EmailAuthProvider.PROVIDER_ID;
31+
readonly providerId = EmailAuthProvider.PROVIDER_ID;
3132

3233
static credential(
3334
email: string,
@@ -37,7 +38,6 @@ export class EmailAuthProvider implements externs.EmailAuthProvider {
3738
return new EmailAuthCredential(
3839
email,
3940
password,
40-
EmailAuthProvider.PROVIDER_ID,
4141
signInMethod || this.EMAIL_PASSWORD_SIGN_IN_METHOD
4242
);
4343
}
@@ -48,24 +48,20 @@ export class EmailAuthProvider implements externs.EmailAuthProvider {
4848
emailLink: string
4949
): EmailAuthCredential {
5050
const actionCodeUrl = ActionCodeURL._fromLink(auth, emailLink);
51-
if (!actionCodeUrl) {
52-
throw AUTH_ERROR_FACTORY.create(AuthErrorCode.ARGUMENT_ERROR, {
53-
appName: auth.name
54-
});
55-
}
51+
assert(actionCodeUrl, auth.name, AuthErrorCode.ARGUMENT_ERROR);
5652

5753
// Check if the tenant ID in the email link matches the tenant ID on Auth
5854
// instance.
59-
if (actionCodeUrl.tenantId !== (auth.tenantId || null)) {
60-
throw AUTH_ERROR_FACTORY.create(AuthErrorCode.TENANT_ID_MISMATCH, {
61-
appName: auth.name
62-
});
63-
}
55+
assert(
56+
actionCodeUrl.tenantId === (auth.tenantId || null),
57+
auth.name,
58+
AuthErrorCode.TENANT_ID_MISMATCH
59+
);
6460

6561
return this.credential(
6662
email,
6763
actionCodeUrl.code,
6864
EmailAuthProvider.EMAIL_LINK_SIGN_IN_METHOD
6965
);
7066
}
71-
}
67+
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ import {
3636
signInWithEmailAndPassword
3737
} from './email_and_password';
3838
import { APIUserInfo } from '../../api/account_management/account';
39-
import { SignInMethod, OperationType, ProviderId } from '@firebase/auth-types-exp';
39+
import {
40+
SignInMethod,
41+
OperationType,
42+
ProviderId
43+
} from '@firebase/auth-types-exp';
4044

4145
use(chaiAsPromised);
4246
use(sinonChai);
@@ -342,11 +346,15 @@ describe('core/strategies/email_and_password/signInWithEmailAndPassword', () =>
342346
afterEach(mockFetch.tearDown);
343347

344348
it('should sign in the user', async () => {
345-
const { credential, user, operationType } = await signInWithEmailAndPassword(auth, 'some-email', 'some-password');
349+
const {
350+
credential,
351+
user,
352+
operationType
353+
} = await signInWithEmailAndPassword(auth, 'some-email', 'some-password');
346354
expect(credential?.providerId).to.eq(ProviderId.PASSWORD);
347355
expect(credential?.signInMethod).to.eq(SignInMethod.EMAIL_PASSWORD);
348356
expect(operationType).to.eq(OperationType.SIGN_IN);
349357
expect(user.uid).to.eq(serverUser.localId);
350358
expect(user.isAnonymous).to.be.false;
351359
});
352-
});
360+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export async function verifyPasswordResetCode(
8585
return data.email!;
8686
}
8787

88-
export async function signInWithEmailAndPassword(
88+
export function signInWithEmailAndPassword(
8989
auth: externs.Auth,
9090
email: string,
9191
password: string

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ import { Endpoint } from '../../api';
2828
import { ServerError } from '../../api/errors';
2929
import { Operation } from '../../model/action_code_info';
3030
import { Auth } from '../../model/auth';
31-
import { isSignInWithEmailLink, sendSignInLinkToEmail, signInWithEmailLink } from './email_link';
32-
import { ProviderId, SignInMethod, OperationType } from '@firebase/auth-types-exp';
31+
import {
32+
isSignInWithEmailLink,
33+
sendSignInLinkToEmail,
34+
signInWithEmailLink
35+
} from './email_link';
36+
import {
37+
ProviderId,
38+
SignInMethod,
39+
OperationType
40+
} from '@firebase/auth-types-exp';
3341
import { APIUserInfo } from '../../api/account_management/account';
3442

3543
use(chaiAsPromised);
@@ -225,11 +233,15 @@ describe('core/strategies/email_and_password/signInWithEmailLink', () => {
225233
'continueUrl=' +
226234
encodeURIComponent(continueUrl) +
227235
'&languageCode=en&state=bla';
228-
const { credential, user, operationType } = await signInWithEmailLink(auth, 'some-email', actionLink);
236+
const { credential, user, operationType } = await signInWithEmailLink(
237+
auth,
238+
'some-email',
239+
actionLink
240+
);
229241
expect(credential?.providerId).to.eq(ProviderId.PASSWORD);
230242
expect(credential?.signInMethod).to.eq(SignInMethod.EMAIL_LINK);
231243
expect(operationType).to.eq(OperationType.SIGN_IN);
232244
expect(user.uid).to.eq(serverUser.localId);
233245
expect(user.isAnonymous).to.be.false;
234246
});
235-
});
247+
});

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { _getCurrentUrl } from '../util/location';
2626
import { setActionCodeSettingsOnRequest } from './action_code_settings';
2727
import { signInWithCredential } from './credential';
2828

29-
3029
export async function sendSignInLinkToEmail(
3130
auth: externs.Auth,
3231
email: string,
@@ -55,9 +54,13 @@ export async function signInWithEmailLink(
5554
auth: externs.Auth,
5655
email: string,
5756
emailLink?: string
58-
): Promise<externs.UserCredential> {
57+
): Promise<externs.UserCredential> {
5958
return signInWithCredential(
6059
auth,
61-
EmailAuthProvider.credentialWithLink(auth as Auth, email, emailLink || _getCurrentUrl())
60+
EmailAuthProvider.credentialWithLink(
61+
auth as Auth,
62+
email,
63+
emailLink || _getCurrentUrl()
64+
)
6265
);
63-
}
66+
}

packages-exp/auth-types-exp/index.d.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ export abstract class AuthCredential {
193193

194194
export abstract class OAuthCredential extends AuthCredential {
195195
static fromJSON(json: object | string): OAuthCredential | null;
196-
196+
197197
readonly accessToken?: string;
198198
readonly idToken?: string;
199199
readonly secret?: string;
200200
}
201201

202202
export abstract class PhoneAuthCredential extends AuthCredential {
203-
static fromJSON ( json : object | string ) : PhoneAuthCredential | null;
203+
static fromJSON(json: object | string): PhoneAuthCredential | null;
204204
}
205205

206206
export const enum OperationType {
@@ -239,26 +239,26 @@ export interface AuthProvider {
239239
readonly providerId: ProviderId;
240240
}
241241

242-
/**
242+
/**
243243
* A provider for generating phone credentials
244244
*/
245245
export class PhoneAuthProvider implements AuthProvider {
246-
static readonly PROVIDER_ID: string;
247-
static readonly PHONE_SIGN_IN_METHOD: string;
248-
static credential(
249-
verificationId: string,
250-
verificationCode: string
251-
): AuthCredential;
252-
253-
constructor(auth?: Auth | null);
254-
255-
readonly providerId: ProviderId;
256-
257-
verifyPhoneNumber(
258-
phoneNumber: string,
259-
applicationVerifier: ApplicationVerifier,
260-
/* multiFactorSession?: MultiFactorSession */
261-
): Promise<string>;
246+
static readonly PROVIDER_ID: string;
247+
static readonly PHONE_SIGN_IN_METHOD: string;
248+
static credential(
249+
verificationId: string,
250+
verificationCode: string
251+
): AuthCredential;
252+
253+
constructor(auth?: Auth | null);
254+
255+
readonly providerId: ProviderId;
256+
257+
verifyPhoneNumber(
258+
phoneNumber: string,
259+
applicationVerifier: ApplicationVerifier
260+
/* multiFactorSession?: MultiFactorSession */
261+
): Promise<string>;
262262
}
263263

264264
/**
@@ -270,6 +270,10 @@ export abstract class EmailAuthProvider implements AuthProvider {
270270
static readonly EMAIL_PASSWORD_SIGN_IN_METHOD: string;
271271
static readonly EMAIL_LINK_SIGN_IN_METHOD: string;
272272
static credential(email: string, password: string): AuthCredential;
273-
static credentialWithLink(auth: Auth, email: string, emailLink: string): AuthCredential;
273+
static credentialWithLink(
274+
auth: Auth,
275+
email: string,
276+
emailLink: string
277+
): AuthCredential;
274278
readonly providerId: ProviderId;
275-
}
279+
}

0 commit comments

Comments
 (0)