Skip to content

Commit 175535b

Browse files
committed
Formatting
1 parent 2cbb270 commit 175535b

File tree

8 files changed

+108
-40
lines changed

8 files changed

+108
-40
lines changed

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

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

2020
import {
21-
updateEmailPassword as apiUpdateEmailPassword, UpdateEmailPasswordRequest
21+
updateEmailPassword as apiUpdateEmailPassword,
22+
UpdateEmailPasswordRequest
2223
} from '../../api/account_management/email_and_password';
2324
import { updateProfile as apiUpdateProfile } from '../../api/account_management/profile';
2425
import { User } from '../../model/user';
@@ -41,7 +42,10 @@ export async function updateProfile(
4142
const user = externUser as User;
4243
const idToken = await user.getIdToken();
4344
const profileRequest = { idToken, displayName, photoUrl };
44-
const response = await _logoutIfInvalidated(user, apiUpdateProfile(user.auth, profileRequest));
45+
const response = await _logoutIfInvalidated(
46+
user,
47+
apiUpdateProfile(user.auth, profileRequest)
48+
);
4549

4650
user.displayName = response.displayName || null;
4751
user.photoURL = response.photoUrl || null;
@@ -91,6 +95,9 @@ async function updateEmailOrPassword(
9195
request.password = password;
9296
}
9397

94-
const response = await _logoutIfInvalidated(user, apiUpdateEmailPassword(auth, request));
98+
const response = await _logoutIfInvalidated(
99+
user,
100+
apiUpdateEmailPassword(auth, request)
101+
);
95102
await user._updateTokensIfNecessary(response, /* reload */ true);
96103
}

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
import { expect, use } from 'chai';
219
import * as chaiAsPromised from 'chai-as-promised';
320

@@ -22,12 +39,14 @@ describe('src/core/user/invalidation', () => {
2239
});
2340

2441
function makeError(code: AuthErrorCode): FirebaseError {
25-
return AUTH_ERROR_FACTORY.create(code, {appName: auth.name});
42+
return AUTH_ERROR_FACTORY.create(code, { appName: auth.name });
2643
}
2744

2845
it('leaves non-invalidation errors alone', async () => {
2946
const error = makeError(AuthErrorCode.TOO_MANY_ATTEMPTS_TRY_LATER);
30-
await expect(_logoutIfInvalidated(user, Promise.reject(error))).to.be.rejectedWith(error);
47+
await expect(
48+
_logoutIfInvalidated(user, Promise.reject(error))
49+
).to.be.rejectedWith(error);
3150
expect(auth.currentUser).to.eq(user);
3251
});
3352

@@ -38,13 +57,17 @@ describe('src/core/user/invalidation', () => {
3857

3958
it('logs out the user if the error is user_disabled', async () => {
4059
const error = makeError(AuthErrorCode.USER_DISABLED);
41-
await expect(_logoutIfInvalidated(user, Promise.reject(error))).to.be.rejectedWith(error);
60+
await expect(
61+
_logoutIfInvalidated(user, Promise.reject(error))
62+
).to.be.rejectedWith(error);
4263
expect(auth.currentUser).to.be.null;
4364
});
4465

4566
it('logs out the user if the error is token_expired', async () => {
4667
const error = makeError(AuthErrorCode.TOKEN_EXPIRED);
47-
await expect(_logoutIfInvalidated(user, Promise.reject(error))).to.be.rejectedWith(error);
68+
await expect(
69+
_logoutIfInvalidated(user, Promise.reject(error))
70+
).to.be.rejectedWith(error);
4871
expect(auth.currentUser).to.be.null;
4972
});
5073

@@ -58,8 +81,10 @@ describe('src/core/user/invalidation', () => {
5881

5982
it('does not log out user2 if the error is user_disabled', async () => {
6083
const error = makeError(AuthErrorCode.USER_DISABLED);
61-
await expect(_logoutIfInvalidated(user, Promise.reject(error))).to.be.rejectedWith(error);
84+
await expect(
85+
_logoutIfInvalidated(user, Promise.reject(error))
86+
).to.be.rejectedWith(error);
6287
expect(auth.currentUser).to.eq(user2);
6388
});
6489
});
65-
});
90+
});

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
import { FirebaseError } from '@firebase/util';
219

320
import { User } from '../../model/user';
421
import { AuthErrorCode } from '../errors';
522

6-
export async function _logoutIfInvalidated<T>(user: User, promise: Promise<T>): Promise<T> {
23+
export async function _logoutIfInvalidated<T>(
24+
user: User,
25+
promise: Promise<T>
26+
): Promise<T> {
727
try {
828
return await promise;
929
} catch (e) {
@@ -17,7 +37,9 @@ export async function _logoutIfInvalidated<T>(user: User, promise: Promise<T>):
1737
}
1838
}
1939

20-
function isUserInvalidated({code}: FirebaseError): boolean {
21-
return code === `auth/${AuthErrorCode.USER_DISABLED}` ||
22-
code === `auth/${AuthErrorCode.TOKEN_EXPIRED}`;
23-
}
40+
function isUserInvalidated({ code }: FirebaseError): boolean {
41+
return (
42+
code === `auth/${AuthErrorCode.USER_DISABLED}` ||
43+
code === `auth/${AuthErrorCode.TOKEN_EXPIRED}`
44+
);
45+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export async function _link(
6262
user: User,
6363
credential: AuthCredential
6464
): Promise<UserCredential> {
65-
const response = await _logoutIfInvalidated(user, credential._linkToIdToken(
66-
user.auth,
67-
await user.getIdToken()
68-
));
65+
const response = await _logoutIfInvalidated(
66+
user,
67+
credential._linkToIdToken(user.auth, await user.getIdToken())
68+
);
6969
return UserCredentialImpl._forOperation(
7070
user,
7171
externs.OperationType.LINK,

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ export async function _reauthenticate(
3434
const operationType = OperationType.REAUTHENTICATE;
3535

3636
try {
37-
const response = await _logoutIfInvalidated(user, _processCredentialSavingMfaContextIfNecessary(
38-
user.auth,
39-
operationType,
40-
credential,
41-
user
42-
));
37+
const response = await _logoutIfInvalidated(
38+
user,
39+
_processCredentialSavingMfaContextIfNecessary(
40+
user.auth,
41+
operationType,
42+
credential,
43+
user
44+
)
45+
);
4346
assert(response.idToken, AuthErrorCode.INTERNAL_ERROR, { appName });
4447
const parsed = _parseToken(response.idToken);
4548
assert(parsed, AuthErrorCode.INTERNAL_ERROR, { appName });

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

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

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

20-
import { getAccountInfo, ProviderUserInfo } from '../../api/account_management/account';
20+
import {
21+
getAccountInfo,
22+
ProviderUserInfo
23+
} from '../../api/account_management/account';
2124
import { User } from '../../model/user';
2225
import { AuthErrorCode } from '../errors';
2326
import { assert } from '../util/assert';
@@ -27,7 +30,10 @@ import { UserMetadata } from './user_metadata';
2730
export async function _reloadWithoutSaving(user: User): Promise<void> {
2831
const auth = user.auth;
2932
const idToken = await user.getIdToken();
30-
const response = await _logoutIfInvalidated(user, getAccountInfo(auth, { idToken }));
33+
const response = await _logoutIfInvalidated(
34+
user,
35+
getAccountInfo(auth, { idToken })
36+
);
3137

3238
assert(response?.users.length, AuthErrorCode.INTERNAL_ERROR, {
3339
appName: auth.name

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import * as externs from '@firebase/auth-types-exp';
1919
import { NextFn } from '@firebase/util';
2020

21-
import { APIUserInfo, deleteAccount } from '../../api/account_management/account';
21+
import {
22+
APIUserInfo,
23+
deleteAccount
24+
} from '../../api/account_management/account';
2225
import { FinalizeMfaResponse } from '../../api/authentication/mfa';
2326
import { Auth } from '../../model/auth';
2427
import { IdTokenResponse } from '../../model/id_token';
@@ -82,10 +85,10 @@ export class UserImpl implements User {
8285
}
8386

8487
async getIdToken(forceRefresh?: boolean): Promise<string> {
85-
const accessToken = await _logoutIfInvalidated(this, this.stsTokenManager.getToken(
86-
this.auth,
87-
forceRefresh
88-
));
88+
const accessToken = await _logoutIfInvalidated(
89+
this,
90+
this.stsTokenManager.getToken(this.auth, forceRefresh)
91+
);
8992
assert(accessToken, AuthErrorCode.INTERNAL_ERROR, {
9093
appName: this.auth.name
9194
});

packages-exp/auth-exp/src/mfa/mfa_user.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,10 @@ export class MultiFactorUser implements externs.MultiFactorUser {
5151
): Promise<void> {
5252
const assertion = assertionExtern as MultiFactorAssertion;
5353
const session = (await this.getSession()) as MultiFactorSession;
54-
const finalizeMfaResponse = await _logoutIfInvalidated(this.user, assertion._process(
55-
this.user.auth,
56-
session,
57-
displayName
58-
));
54+
const finalizeMfaResponse = await _logoutIfInvalidated(
55+
this.user,
56+
assertion._process(this.user.auth, session, displayName)
57+
);
5958
// New tokens will be issued after enrollment of the new second factors.
6059
// They need to be updated on the user.
6160
await this.user._updateTokensIfNecessary(finalizeMfaResponse);
@@ -69,10 +68,13 @@ export class MultiFactorUser implements externs.MultiFactorUser {
6968
const mfaEnrollmentId =
7069
typeof infoOrUid === 'string' ? infoOrUid : infoOrUid.uid;
7170
const idToken = await this.user.getIdToken();
72-
const idTokenResponse = await _logoutIfInvalidated(this.user, withdrawMfa(this.user.auth, {
73-
idToken,
74-
mfaEnrollmentId
75-
}));
71+
const idTokenResponse = await _logoutIfInvalidated(
72+
this.user,
73+
withdrawMfa(this.user.auth, {
74+
idToken,
75+
mfaEnrollmentId
76+
})
77+
);
7678
// Remove the second factor from the user's list.
7779
this.enrolledFactors = this.enrolledFactors.filter(
7880
({ uid }) => uid !== mfaEnrollmentId

0 commit comments

Comments
 (0)