Skip to content

Commit 3bc7a88

Browse files
committed
Use getAuth for default auth instance and initializeAuth for locationData
1 parent d03b3fa commit 3bc7a88

File tree

4 files changed

+13
-27
lines changed

4 files changed

+13
-27
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
NextOrObserver,
3131
Persistence,
3232
PopupRedirectResolver,
33-
RegionData,
33+
LocationData,
3434
User,
3535
UserCredential,
3636
CompleteFn,
@@ -127,7 +127,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
127127
| undefined = undefined;
128128
_persistenceManagerAvailable: Promise<void>;
129129
readonly name: string;
130-
readonly regionData: RegionData;
130+
readonly locationData: LocationData;
131131

132132
// Tracks the last notified UID for state change listeners to prevent
133133
// repeated calls to the callbacks. Undefined means it's never been
@@ -143,7 +143,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
143143
private readonly heartbeatServiceProvider: Provider<'heartbeat'>,
144144
private readonly appCheckServiceProvider: Provider<AppCheckInternalComponentName>,
145145
public readonly config: ConfigInternal,
146-
regionData?: RegionData
146+
locationData?: LocationData
147147
) {
148148
this.name = app.name;
149149
this.clientVersion = config.sdkClientVersion;
@@ -152,7 +152,7 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
152152
this._persistenceManagerAvailable = new Promise<void>(
153153
resolve => (this._resolvePersistenceManagerAvailable = resolve)
154154
);
155-
this.regionData = regionData ?? {};
155+
this.locationData = locationData ?? {};
156156
}
157157

158158
_initializeWithPersistence(

packages/auth/src/core/auth/register.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
6969
const appCheckServiceProvider =
7070
container.getProvider<'app-check-internal'>('app-check-internal');
7171
const { apiKey, authDomain } = app.options;
72-
const regionData = deps?.regionData ?? { location: '', tenantId: '' };
72+
const locationData = deps?.locationData ?? { location: '', tenantId: '' };
7373
console.log("inside register auth new component");
7474
_assert(
7575
apiKey && !apiKey.includes(':'),
@@ -81,7 +81,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
8181
apiKey,
8282
authDomain,
8383
clientPlatform,
84-
apiHost: regionData.location ? DefaultConfig.REGIONAL_API_HOST : DefaultConfig.API_HOST,
84+
apiHost: locationData.location ? DefaultConfig.REGIONAL_API_HOST : DefaultConfig.API_HOST,
8585
tokenApiHost: DefaultConfig.TOKEN_API_HOST,
8686
apiScheme: DefaultConfig.API_SCHEME,
8787
sdkClientVersion: _getClientVersion(clientPlatform)
@@ -92,7 +92,7 @@ export function registerAuth(clientPlatform: ClientPlatform): void {
9292
heartbeatServiceProvider,
9393
appCheckServiceProvider,
9494
config,
95-
regionData
95+
locationData
9696
);
9797
_initializeAuthInstance(authInstance, deps);
9898

packages/auth/src/model/public_types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,10 +1260,10 @@ export interface Dependencies {
12601260
* Which {@link AuthErrorMap} to use.
12611261
*/
12621262
errorMap?: AuthErrorMap;
1263-
regionData?: RegionData
1263+
locationData?: LocationData;
12641264
}
12651265

1266-
export interface RegionData {
1266+
export interface LocationData {
12671267
location?: string;
12681268
tenantId?: string;
12691269
}

packages/auth/src/platform_browser/index.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ import { browserLocalPersistence } from './persistence/local_storage';
2929
import { browserSessionPersistence } from './persistence/session_storage';
3030
import { indexedDBLocalPersistence } from './persistence/indexed_db';
3131
import { browserPopupRedirectResolver } from './popup_redirect';
32-
import { Auth, Dependencies, RegionData, User } from '../model/public_types';
33-
import { deepEqual, getDefaultEmulatorHost, getExperimentalSetting } from '@firebase/util';
32+
import { Auth, User } from '../model/public_types';
33+
import { getDefaultEmulatorHost, getExperimentalSetting } from '@firebase/util';
3434
import { _setExternalJSProvider } from './load_js';
35-
import { _createError, _fail } from '../core/util/assert';
35+
import { _createError } from '../core/util/assert';
3636
import { AuthErrorCode } from '../core/errors';
37-
import { AuthImpl } from '../core/auth/auth_impl';
3837

3938
const DEFAULT_ID_TOKEN_MAX_AGE = 5 * 60;
4039
const authIdTokenMaxAge =
@@ -74,22 +73,10 @@ const mintCookieFactory = (url: string) => async (user: User | null) => {
7473
*
7574
* @public
7675
*/
77-
export function getAuth(app: FirebaseApp = getApp(), regionData?: RegionData): Auth {
76+
export function getAuth(app: FirebaseApp = getApp()): Auth {
7877
const provider = _getProvider(app, 'auth');
7978

8079
if (provider.isInitialized()) {
81-
const auth = provider.getImmediate() as AuthImpl;
82-
// Extract previously used regionData from initialization
83-
const initialOptions = provider.getOptions() as Dependencies;
84-
85-
const previousRegionData = initialOptions?.regionData ?? {};
86-
const currentRegionData = regionData ?? {};
87-
if (deepEqual(previousRegionData, currentRegionData)) {
88-
return auth;
89-
} else {
90-
_fail(auth, AuthErrorCode.ALREADY_INITIALIZED);
91-
}
92-
9380
return provider.getImmediate();
9481
}
9582

@@ -100,7 +87,6 @@ export function getAuth(app: FirebaseApp = getApp(), regionData?: RegionData): A
10087
browserLocalPersistence,
10188
browserSessionPersistence
10289
],
103-
regionData
10490
});
10591

10692
const authTokenSyncPath = getExperimentalSetting('authTokenSyncURL');

0 commit comments

Comments
 (0)