-
Notifications
You must be signed in to change notification settings - Fork 938
Fix throttling for App Check to prevent unnecessary requests to backend #6439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/app-check': minor | ||
--- | ||
|
||
Fix logic to trigger app check throttling |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,11 +41,11 @@ import * as util from './util'; | |
import { logger } from './logger'; | ||
import { getState, clearState, setState, getDebugState } from './state'; | ||
import { AppCheckTokenListener } from './public-types'; | ||
import { Deferred, FirebaseError } from '@firebase/util'; | ||
import { Deferred } from '@firebase/util'; | ||
import { ReCaptchaEnterpriseProvider, ReCaptchaV3Provider } from './providers'; | ||
import { AppCheckService } from './factory'; | ||
import { ListenerType } from './types'; | ||
import { AppCheckError } from './errors'; | ||
import { AppCheckError, ERROR_FACTORY } from './errors'; | ||
|
||
const fakeRecaptchaToken = 'fake-recaptcha-token'; | ||
const fakeRecaptchaAppCheckToken = { | ||
|
@@ -396,11 +396,9 @@ describe('internal api', () => { | |
const warnStub = stub(logger, 'warn'); | ||
stub(client, 'exchangeToken').returns( | ||
Promise.reject( | ||
new FirebaseError( | ||
AppCheckError.FETCH_STATUS_ERROR, | ||
'test error msg', | ||
{ httpStatus: 503 } | ||
) | ||
ERROR_FACTORY.create(AppCheckError.FETCH_STATUS_ERROR, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing the test! |
||
httpStatus: 503 | ||
}) | ||
) | ||
); | ||
|
||
|
@@ -424,11 +422,9 @@ describe('internal api', () => { | |
const warnStub = stub(logger, 'warn'); | ||
stub(client, 'exchangeToken').returns( | ||
Promise.reject( | ||
new FirebaseError( | ||
AppCheckError.FETCH_STATUS_ERROR, | ||
'test error msg', | ||
{ httpStatus: 403 } | ||
) | ||
ERROR_FACTORY.create(AppCheckError.FETCH_STATUS_ERROR, { | ||
httpStatus: 403 | ||
}) | ||
) | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,10 @@ export class ReCaptchaV3Provider implements AppCheckProvider { | |
this._heartbeatServiceProvider! | ||
); | ||
} catch (e) { | ||
if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { | ||
console.log({ coder: (e as FirebaseError).code }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this left over from debugging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! Good catch. Removing it now |
||
if ( | ||
(e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR) | ||
) { | ||
this._throttleData = setBackoff( | ||
Number((e as FirebaseError).customData?.httpStatus), | ||
this._throttleData | ||
|
@@ -167,7 +170,9 @@ export class ReCaptchaEnterpriseProvider implements AppCheckProvider { | |
this._heartbeatServiceProvider! | ||
); | ||
} catch (e) { | ||
if ((e as FirebaseError).code === AppCheckError.FETCH_STATUS_ERROR) { | ||
if ( | ||
(e as FirebaseError).code?.includes(AppCheckError.FETCH_STATUS_ERROR) | ||
) { | ||
this._throttleData = setBackoff( | ||
Number((e as FirebaseError).customData?.httpStatus), | ||
this._throttleData | ||
|
Uh oh!
There was an error while loading. Please reload this page.