Skip to content

Commit 1ff891c

Browse files
authored
Reorder RecaptchaVerifier params so auth is the first param (#7326)
1 parent 4f904bf commit 1ff891c

File tree

10 files changed

+31
-28
lines changed

10 files changed

+31
-28
lines changed

.changeset/old-badgers-mate.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@firebase/auth': major
3+
'@firebase/auth-compat': patch
4+
'firebase': major
5+
---
6+
7+
Reorder RecaptchaVerifier parameters so auth is the first parameter

common/api-review/auth.api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ export interface RecaptchaParameters {
681681
//
682682
// @public
683683
export class RecaptchaVerifier implements ApplicationVerifierInternal {
684-
constructor(containerOrId: HTMLElement | string, parameters: RecaptchaParameters, authExtern: Auth);
684+
constructor(authExtern: Auth, containerOrId: HTMLElement | string, parameters?: RecaptchaParameters);
685685
clear(): void;
686686
// Warning: (ae-forgotten-export) The symbol "ReCaptchaLoader" needs to be exported by the entry point index.d.ts
687687
//

docs-devsite/auth.recaptchaverifier.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export declare class RecaptchaVerifier implements ApplicationVerifierInternal
2525
2626
| Constructor | Modifiers | Description |
2727
| --- | --- | --- |
28-
| [(constructor)(containerOrId, parameters, authExtern)](./auth.recaptchaverifier.md#recaptchaverifierconstructor) | | Constructs a new instance of the <code>RecaptchaVerifier</code> class |
28+
| [(constructor)(authExtern, containerOrId, parameters)](./auth.recaptchaverifier.md#recaptchaverifierconstructor) | | Constructs a new instance of the <code>RecaptchaVerifier</code> class |
2929
3030
## Properties
3131
@@ -50,16 +50,16 @@ Check the reCAPTCHA docs for a comprehensive list. All parameters are accepted e
5050
<b>Signature:</b>
5151
5252
```typescript
53-
constructor(containerOrId: HTMLElement | string, parameters: RecaptchaParameters, authExtern: Auth);
53+
constructor(authExtern: Auth, containerOrId: HTMLElement | string, parameters?: RecaptchaParameters);
5454
```
5555
5656
### Parameters
5757
5858
| Parameter | Type | Description |
5959
| --- | --- | --- |
60+
| authExtern | [Auth](./auth.auth.md#auth_interface) | The corresponding Firebase [Auth](./auth.auth.md#auth_interface) instance. |
6061
| containerOrId | HTMLElement \| string | The reCAPTCHA container parameter. |
6162
| parameters | [RecaptchaParameters](./auth.recaptchaparameters.md#recaptchaparameters_interface) | The optional reCAPTCHA parameters. |
62-
| authExtern | [Auth](./auth.auth.md#auth_interface) | The corresponding Firebase [Auth](./auth.auth.md#auth_interface) instance. |
6363
6464
## RecaptchaVerifier.type
6565

packages/auth-compat/src/recaptcha_verifier.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ export class RecaptchaVerifier
3737
appName: app.name
3838
});
3939
this._delegate = new exp.RecaptchaVerifier(
40-
container,
41-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
42-
parameters as any,
43-
4440
// TODO: remove ts-ignore when moving types from auth-types to auth-compat
4541
// @ts-ignore
46-
app.auth!()
42+
app.auth!(),
43+
container,
44+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
45+
parameters as any
4746
);
4847
this.type = this._delegate.type;
4948
}

packages/auth/demo/src/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,9 @@ function onSignInWithGenericIdPCredential() {
521521
function makeApplicationVerifier(submitButtonId) {
522522
const container =
523523
recaptchaSize === 'invisible' ? submitButtonId : 'recaptcha-container';
524-
applicationVerifier = new RecaptchaVerifier(
525-
container,
526-
{ 'size': recaptchaSize },
527-
auth
528-
);
524+
applicationVerifier = new RecaptchaVerifier(auth, container, {
525+
'size': recaptchaSize
526+
});
529527
}
530528

531529
/**

packages/auth/src/platform_browser/providers/phone.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ describe('platform_browser/providers/phone', () => {
4545
});
4646

4747
const verifier = new RecaptchaVerifier(
48+
auth,
4849
document.createElement('div'),
49-
{},
50-
auth
50+
{}
5151
);
5252
sinon
5353
.stub(verifier, 'verify')

packages/auth/src/platform_browser/recaptcha/recaptcha_verifier.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('platform_browser/recaptcha/recaptcha_verifier', () => {
5050
auth.languageCode = 'fr';
5151
container = document.createElement('div');
5252
parameters = {};
53-
verifier = new RecaptchaVerifier(container, parameters, auth);
53+
verifier = new RecaptchaVerifier(auth, container, parameters);
5454
// The verifier will have set the parameters.callback field to be the wrapped callback
5555

5656
mockEndpoint(Endpoint.GET_RECAPTCHA_PARAM, {
@@ -134,7 +134,7 @@ describe('platform_browser/recaptcha/recaptcha_verifier', () => {
134134
}
135135
};
136136

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

152-
verifier = new RecaptchaVerifier(container, parameters, auth);
152+
verifier = new RecaptchaVerifier(auth, container, parameters);
153153
const expected = await verifier.verify();
154154
expect(token).to.eq(expected);
155155

packages/auth/src/platform_browser/recaptcha/recaptcha_verifier.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class RecaptchaVerifier implements ApplicationVerifierInternal {
7070
private recaptcha: Recaptcha | null = null;
7171

7272
/**
73+
* @param authExtern - The corresponding Firebase {@link Auth} instance.
7374
*
7475
* @param containerOrId - The reCAPTCHA container parameter.
7576
*
@@ -86,15 +87,13 @@ export class RecaptchaVerifier implements ApplicationVerifierInternal {
8687
* the sitekey. Firebase Auth backend provisions a reCAPTCHA for each project and will
8788
* configure this upon rendering. For an invisible reCAPTCHA, a size key must have the value
8889
* 'invisible'.
89-
*
90-
* @param authExtern - The corresponding Firebase {@link Auth} instance.
9190
*/
9291
constructor(
92+
authExtern: Auth,
9393
containerOrId: HTMLElement | string,
9494
private readonly parameters: RecaptchaParameters = {
9595
...DEFAULT_PARAMS
96-
},
97-
authExtern: Auth
96+
}
9897
) {
9998
this.auth = _castAuth(authExtern);
10099
this.isInvisible = this.parameters.size === 'invisible';

packages/auth/src/platform_browser/strategies/phone.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('platform_browser/strategies/phone', () => {
6060
sessionInfo: 'session-info'
6161
});
6262

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

packages/auth/test/integration/flows/phone.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ describe('Integration test: phone auth', () => {
7373
fakeRecaptchaContainer = document.createElement('div');
7474
document.body.appendChild(fakeRecaptchaContainer);
7575
verifier = new RecaptchaVerifier(
76+
auth,
7677
fakeRecaptchaContainer,
77-
undefined as any,
78-
auth
78+
undefined as any
7979
);
8080
});
8181

@@ -87,9 +87,9 @@ describe('Integration test: phone auth', () => {
8787
function resetVerifier(): void {
8888
verifier.clear();
8989
verifier = new RecaptchaVerifier(
90+
auth,
9091
fakeRecaptchaContainer,
91-
undefined as any,
92-
auth
92+
undefined as any
9393
);
9494
}
9595

0 commit comments

Comments
 (0)