Skip to content

Commit 4a48bd6

Browse files
committed
Rebase conflicts & PR feedback
1 parent 1fcbfec commit 4a48bd6

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class AuthImpl implements Auth {
9797
}
9898

9999
private get assertedPersistence(): PersistenceUserManager {
100-
return assert(this.persistenceManager, this.name);
100+
assert(this.persistenceManager, this.name);
101+
return this.persistenceManager;
101102
}
102103
}
103104

@@ -110,8 +111,9 @@ export function initializeAuth(
110111
const { apiKey, authDomain } = app.options;
111112

112113
// TODO: platform needs to be determined using heuristics
114+
assert(apiKey, app.name, AuthErrorCode.INVALID_API_KEY);
113115
const config: Config = {
114-
apiKey: assert(apiKey, app.name, AuthErrorCode.INVALID_API_KEY),
116+
apiKey,
115117
authDomain,
116118
apiHost: DEFAULT_API_HOST,
117119
apiScheme: DEFAULT_API_SCHEME,

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IdTokenResult } from '../../model/id_token';
2020
import { User } from '../../model/user';
2121
import { PersistedBlob } from '../persistence';
2222
import { ProviderId } from '../providers';
23-
import { assert, assertStringOrUndefined } from '../util/assert';
23+
import { assert } from '../util/assert';
2424
import { StsTokenManager } from './token_manager';
2525

2626
export interface UserParameters {
@@ -34,6 +34,17 @@ export interface UserParameters {
3434
photoURL?: string;
3535
}
3636

37+
38+
function assertStringOrUndefined(
39+
assertion: unknown,
40+
appName: string
41+
): asserts assertion is string | undefined {
42+
assert(
43+
typeof assertion === 'string' || typeof assertion === 'undefined',
44+
appName
45+
);
46+
}
47+
3748
export class UserImpl implements User {
3849
// For the user object, provider is always Firebase.
3950
readonly providerId = ProviderId.FIREBASE;

packages-exp/auth-exp/src/core/util/assert.ts

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

18-
import { SDK_VERSION } from '@firebase/app-exp';
19-
import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../errors';
18+
import { AuthErrorCode, AUTH_ERROR_FACTORY } from '../errors';
2019
import { logError } from './log';
2120

2221
/**
@@ -25,8 +24,8 @@ import { logError } from './log';
2524
* @param appName App name for tagging the error
2625
* @throws FirebaseError
2726
*/
28-
export function fail(appName: string): never {
29-
throw AUTH_ERROR_FACTORY.create(AuthErrorCode.INTERNAL_ERROR, { appName });
27+
export function fail(appName: string, errorCode: AuthErrorCode): never {
28+
throw AUTH_ERROR_FACTORY.create(errorCode, { appName });
3029
}
3130

3231
/**
@@ -35,22 +34,12 @@ export function fail(appName: string): never {
3534
* @param assertion
3635
* @param appName
3736
*/
38-
export function assert(assertion: boolean, appName: string): asserts assertion {
37+
export function assert(assertion: unknown, appName: string, errorCode: AuthErrorCode = AuthErrorCode.INTERNAL_ERROR): asserts assertion {
3938
if (!assertion) {
40-
fail(appName);
39+
fail(appName, errorCode);
4140
}
4241
}
4342

44-
export function assertStringOrUndefined(
45-
assertion: unknown,
46-
appName: string
47-
): asserts assertion is string | undefined {
48-
assert(
49-
typeof assertion === 'string' || typeof assertion === 'undefined',
50-
appName
51-
);
52-
}
53-
5443
/**
5544
* Unconditionally fails, throwing an internal error with the given message.
5645
*
@@ -60,10 +49,10 @@ export function assertStringOrUndefined(
6049
export function debugFail(failure: string): never {
6150
// Log the failure in addition to throw an exception, just in case the
6251
// exception is swallowed.
63-
const message = `AUTH (${SDK_VERSION}) INTERNAL ASSERTION FAILED: ` + failure;
52+
const message = `INTERNAL ASSERTION FAILED: ` + failure;
6453
logError(message);
6554

66-
// NOTE: We don't use FirestoreError here because these are internal failures
55+
// NOTE: We don't use FirebaseError here because these are internal failures
6756
// that cannot be handled by the user. (Also it would create a circular
6857
// dependency between the error and assert modules which doesn't work.)
6958
throw new Error(message);

0 commit comments

Comments
 (0)