Skip to content

Reorder RecaptchaVerifier params so auth is the first param #7326

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

Merged
merged 4 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/old-badgers-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@firebase/auth': major
'@firebase/auth-compat': patch
'firebase': major
---

Reorder RecaptchaVerifier parameters so auth is the first parameter
2 changes: 1 addition & 1 deletion common/api-review/auth.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ export interface RecaptchaParameters {
//
// @public
export class RecaptchaVerifier implements ApplicationVerifierInternal {
constructor(containerOrId: HTMLElement | string, parameters: RecaptchaParameters, authExtern: Auth);
constructor(authExtern: Auth, containerOrId: HTMLElement | string, parameters?: RecaptchaParameters);
clear(): void;
// Warning: (ae-forgotten-export) The symbol "ReCaptchaLoader" needs to be exported by the entry point index.d.ts
//
Expand Down
6 changes: 3 additions & 3 deletions docs-devsite/auth.recaptchaverifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export declare class RecaptchaVerifier implements ApplicationVerifierInternal

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(containerOrId, parameters, authExtern)](./auth.recaptchaverifier.md#recaptchaverifierconstructor) | | Constructs a new instance of the <code>RecaptchaVerifier</code> class |
| [(constructor)(authExtern, containerOrId, parameters)](./auth.recaptchaverifier.md#recaptchaverifierconstructor) | | Constructs a new instance of the <code>RecaptchaVerifier</code> class |

## Properties

Expand All @@ -48,16 +48,16 @@ Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted e
<b>Signature:</b>

```typescript
constructor(containerOrId: HTMLElement | string, parameters: RecaptchaParameters, authExtern: Auth);
constructor(authExtern: Auth, containerOrId: HTMLElement | string, parameters?: RecaptchaParameters);
```

### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| authExtern | [Auth](./auth.auth.md#auth_interface) | The corresponding Firebase [Auth](./auth.auth.md#auth_interface) instance. |
| containerOrId | HTMLElement \| string | The reCAPTCHA container parameter. |
| parameters | [RecaptchaParameters](./auth.recaptchaparameters.md#recaptchaparameters_interface) | The optional reCAPTCHA parameters. |
| authExtern | [Auth](./auth.auth.md#auth_interface) | The corresponding Firebase [Auth](./auth.auth.md#auth_interface) instance. |

## RecaptchaVerifier.type

Expand Down
9 changes: 4 additions & 5 deletions packages/auth-compat/src/recaptcha_verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ export class RecaptchaVerifier
appName: app.name
});
this._delegate = new exp.RecaptchaVerifier(
container,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters as any,

// TODO: remove ts-ignore when moving types from auth-types to auth-compat
// @ts-ignore
app.auth!()
app.auth!(),
container,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters as any
);
this.type = this._delegate.type;
}
Expand Down
8 changes: 3 additions & 5 deletions packages/auth/demo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,9 @@ function onSignInWithGenericIdPCredential() {
function makeApplicationVerifier(submitButtonId) {
const container =
recaptchaSize === 'invisible' ? submitButtonId : 'recaptcha-container';
applicationVerifier = new RecaptchaVerifier(
container,
{ 'size': recaptchaSize },
auth
);
applicationVerifier = new RecaptchaVerifier(auth, container, {
'size': recaptchaSize
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/src/platform_browser/providers/phone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describe('platform_browser/providers/phone', () => {
});

const verifier = new RecaptchaVerifier(
auth,
document.createElement('div'),
{},
auth
{}
);
sinon
.stub(verifier, 'verify')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('platform_browser/recaptcha/recaptcha_verifier', () => {
auth.languageCode = 'fr';
container = document.createElement('div');
parameters = {};
verifier = new RecaptchaVerifier(container, parameters, auth);
verifier = new RecaptchaVerifier(auth, container, parameters);
// The verifier will have set the parameters.callback field to be the wrapped callback

mockEndpoint(Endpoint.GET_RECAPTCHA_PARAM, {
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('platform_browser/recaptcha/recaptcha_verifier', () => {
}
};

verifier = new RecaptchaVerifier(container, parameters, auth);
verifier = new RecaptchaVerifier(auth, container, parameters);
const expected = await verifier.verify();
expect(token).to.eq(expected);
});
Expand All @@ -149,7 +149,7 @@ describe('platform_browser/recaptcha/recaptcha_verifier', () => {
callback: 'callbackOnWindowObject'
};

verifier = new RecaptchaVerifier(container, parameters, auth);
verifier = new RecaptchaVerifier(auth, container, parameters);
const expected = await verifier.verify();
expect(token).to.eq(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class RecaptchaVerifier implements ApplicationVerifierInternal {
private recaptcha: Recaptcha | null = null;

/**
* @param authExtern - The corresponding Firebase {@link Auth} instance.
*
* @param containerOrId - The reCAPTCHA container parameter.
*
Expand All @@ -83,15 +84,13 @@ export class RecaptchaVerifier implements ApplicationVerifierInternal {
* the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will
* configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value
* 'invisible'.
*
* @param authExtern - The corresponding Firebase {@link Auth} instance.
*/
constructor(
authExtern: Auth,
containerOrId: HTMLElement | string,
private readonly parameters: RecaptchaParameters = {
...DEFAULT_PARAMS
},
authExtern: Auth
}
) {
this.auth = _castAuth(authExtern);
this.isInvisible = this.parameters.size === 'invisible';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('platform_browser/strategies/phone', () => {
sessionInfo: 'session-info'
});

verifier = new RecaptchaVerifier(document.createElement('div'), {}, auth);
verifier = new RecaptchaVerifier(auth, document.createElement('div'), {});
sinon.stub(verifier, 'verify').returns(Promise.resolve('recaptcha-token'));
});

Expand Down
8 changes: 4 additions & 4 deletions packages/auth/test/integration/flows/phone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ describe('Integration test: phone auth', () => {
fakeRecaptchaContainer = document.createElement('div');
document.body.appendChild(fakeRecaptchaContainer);
verifier = new RecaptchaVerifier(
auth,
fakeRecaptchaContainer,
undefined as any,
auth
undefined as any
);
});

Expand All @@ -87,9 +87,9 @@ describe('Integration test: phone auth', () => {
function resetVerifier(): void {
verifier.clear();
verifier = new RecaptchaVerifier(
auth,
fakeRecaptchaContainer,
undefined as any,
auth
undefined as any
);
}

Expand Down