Skip to content

Commit ff61e6c

Browse files
committed
Throw Operation Not Allowed for Invalid Auth Endpoint (#9013)
* Throw not supported exception in _performApiRequest
1 parent d9ef125 commit ff61e6c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/auth/src/api/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const enum HttpHeader {
5454
X_FIREBASE_APP_CHECK = 'X-Firebase-AppCheck'
5555
}
5656

57-
export const enum Endpoint {
57+
export enum Endpoint {
5858
CREATE_AUTH_URI = '/v1/accounts:createAuthUri',
5959
DELETE_ACCOUNT = '/v1/accounts:delete',
6060
RESET_PASSWORD = '/v1/accounts:resetPassword',
@@ -155,6 +155,7 @@ async function performApiRequest<T, V>(
155155
request?: T,
156156
customErrorMap: Partial<ServerErrorMap<ServerError>> = {}
157157
): Promise<V> {
158+
_assertValidEndpointForAuth(auth, path);
158159
return _performFetchWithErrorHandling(auth, customErrorMap, async () => {
159160
let body = {};
160161
let params = {};
@@ -374,6 +375,22 @@ export function _parseEnforcementState(
374375
}
375376
}
376377

378+
function _assertValidEndpointForAuth(
379+
auth: Auth,
380+
path: Endpoint | RegionalEndpoint
381+
): void {
382+
if (
383+
!auth.tenantConfig &&
384+
Object.values(RegionalEndpoint).includes(path as RegionalEndpoint)
385+
) {
386+
throw _operationNotSupportedForInitializedAuthInstance(auth);
387+
}
388+
389+
if (auth.tenantConfig && Object.values(Endpoint).includes(path as Endpoint)) {
390+
throw _operationNotSupportedForInitializedAuthInstance(auth);
391+
}
392+
}
393+
377394
class NetworkTimeout<T> {
378395
// Node timers and browser timers are fundamentally incompatible, but we
379396
// don't care about the value here

0 commit comments

Comments
 (0)