Skip to content

Commit f7cac56

Browse files
renkelvinrenkelvin
renkelvin
andauthored
Ci fix after rebasing from main branch (#7085)
* test * Revert "test" This reverts commit 474b996. * format * lint * non-browser env * yarn docgen devsite * yarn docgen devsite * Update API reports --------- Co-authored-by: renkelvin <[email protected]>
1 parent bce05e2 commit f7cac56

25 files changed

+853
-439
lines changed

common/api-review/auth.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ export function reauthenticateWithPopup(user: User, provider: AuthProvider, reso
665665
// @public
666666
export function reauthenticateWithRedirect(user: User, provider: AuthProvider, resolver?: PopupRedirectResolver): Promise<never>;
667667

668-
// @public
668+
// @public (undocumented)
669669
export interface RecaptchaConfig {
670670
emailPasswordEnabled: boolean;
671671
}

docs-devsite/auth.auth.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface Auth
3838
| Method | Description |
3939
| --- | --- |
4040
| [beforeAuthStateChanged(callback, onAbort)](./auth.auth.md#authbeforeauthstatechanged) | Adds a blocking callback that runs before an auth state change sets a new user. |
41+
| [initializeRecaptchaConfig()](./auth.auth.md#authinitializerecaptchaconfig) | Initializes the reCAPTCHA configuration on the <code>Auth</code> instance. |
4142
| [onAuthStateChanged(nextOrObserver, error, completed)](./auth.auth.md#authonauthstatechanged) | Adds an observer for changes to the user's sign-in state. |
4243
| [onIdTokenChanged(nextOrObserver, error, completed)](./auth.auth.md#authonidtokenchanged) | Adds an observer for changes to the signed-in user's ID token. |
4344
| [setPersistence(persistence)](./auth.auth.md#authsetpersistence) | Changes the type of persistence on the <code>Auth</code> instance. |
@@ -165,6 +166,33 @@ beforeAuthStateChanged(callback: (user: User | null) => void | Promise<void>, on
165166

166167
[Unsubscribe](./util.md#unsubscribe)
167168

169+
## Auth.initializeRecaptchaConfig()
170+
171+
Initializes the reCAPTCHA configuration on the `Auth` instance.
172+
173+
This will initialize reCAPTCHA config of the current Auth session which affects the future auth requests.
174+
175+
The reCAPTCHA config indicates whether the reCAPTCHA verification flow should be triggered for a specific auth provider. Note that this only affect the client auth request but won't override the actual enablement state on the server side.
176+
177+
For example, assume that reCAPTCHA verfication is enabled for Email provider via Cloud console or Admin SDKs. If the enablement is initialized to false via `initializeRecaptchaConfig()`<!-- -->, the auth flow will be started without the reCAPTCHA verfication. This will result in a `reCAPTCHA token missing` error while the SDK will automatically start the auth flow again with the reCAPTCHA verfication flow. Developers can avoid such round trip by enabling the reCAPTCHA flow with this method.
178+
179+
<b>Signature:</b>
180+
181+
```typescript
182+
initializeRecaptchaConfig(): Promise<void>;
183+
```
184+
<b>Returns:</b>
185+
186+
Promise&lt;void&gt;
187+
188+
### Example
189+
190+
191+
```javascript
192+
auth.initializeRecaptchaConfig();
193+
194+
```
195+
168196
## Auth.onAuthStateChanged()
169197

170198
Adds an observer for changes to the user's sign-in state.

docs-devsite/auth.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Firebase Authentication
3131
| [fetchSignInMethodsForEmail(auth, email)](./auth.md#fetchsigninmethodsforemail) | Gets the list of possible sign in methods for the given email address. |
3232
| [getMultiFactorResolver(auth, error)](./auth.md#getmultifactorresolver) | Provides a [MultiFactorResolver](./auth.multifactorresolver.md#multifactorresolver_interface) suitable for completion of a multi-factor flow. |
3333
| [getRedirectResult(auth, resolver)](./auth.md#getredirectresult) | Returns a [UserCredential](./auth.usercredential.md#usercredential_interface) from the redirect-based sign-in flow. |
34+
| [initializeRecaptchaConfig(auth)](./auth.md#initializerecaptchaconfig) | Initializes the reCAPTCHA configuration on the <code>Auth</code> instance. |
3435
| [isSignInWithEmailLink(auth, emailLink)](./auth.md#issigninwithemaillink) | Checks if an incoming link is a sign-in with email link suitable for [signInWithEmailLink()](./auth.md#signinwithemaillink)<!-- -->. |
3536
| [onAuthStateChanged(auth, nextOrObserver, error, completed)](./auth.md#onauthstatechanged) | Adds an observer for changes to the user's sign-in state. |
3637
| [onIdTokenChanged(auth, nextOrObserver, error, completed)](./auth.md#onidtokenchanged) | Adds an observer for changes to the signed-in user's ID token. |
@@ -129,6 +130,7 @@ Firebase Authentication
129130
| [PhoneSingleFactorInfoOptions](./auth.phonesinglefactorinfooptions.md#phonesinglefactorinfooptions_interface) | Options used for single-factor sign-in. |
130131
| [PopupRedirectResolver](./auth.popupredirectresolver.md#popupredirectresolver_interface) | A resolver used for handling DOM specific operations like [signInWithPopup()](./auth.md#signinwithpopup) or [signInWithRedirect()](./auth.md#signinwithredirect)<!-- -->. |
131132
| [ReactNativeAsyncStorage](./auth.reactnativeasyncstorage.md#reactnativeasyncstorage_interface) | Interface for a supplied <code>AsyncStorage</code>. |
133+
| [RecaptchaConfig](./auth.recaptchaconfig.md#recaptchaconfig_interface) | |
132134
| [RecaptchaParameters](./auth.recaptchaparameters.md#recaptchaparameters_interface) | Interface representing reCAPTCHA parameters.<!-- -->See the \[reCAPTCHA docs\](https://developers.google.com/recaptcha/docs/display\#render\_param) for the list of accepted parameters. All parameters are accepted except for <code>sitekey</code>: Firebase Auth provisions a reCAPTCHA for each project and will configure the site key upon rendering.<!-- -->For an invisible reCAPTCHA, set the <code>size</code> key to <code>invisible</code>. |
133135
| [User](./auth.user.md#user_interface) | A user account. |
134136
| [UserCredential](./auth.usercredential.md#usercredential_interface) | A structure containing a [User](./auth.user.md#user_interface)<!-- -->, the [OperationType](./auth.md#operationtype)<!-- -->, and the provider ID. |
@@ -482,6 +484,36 @@ const operationType = result.operationType;
482484

483485
```
484486

487+
## initializeRecaptchaConfig()
488+
489+
Initializes the reCAPTCHA configuration on the `Auth` instance.
490+
491+
This will pull the reCAPTCHA config to the current Auth session and affect future auth requests, which indicates whether the reCAPTCHA verification flow should be triggered for a specific auth provider. If initializeRecaptchaConfig() is not invoked, the auth flow will start without reCAPTCHA verification. But if reCAPTCHA verification is required, the reCAPTCHA config will be automatically pulled internally and the flows will restart. Thus, calling this optional method will reduce the latency of auth flows.
492+
493+
<b>Signature:</b>
494+
495+
```typescript
496+
export declare function initializeRecaptchaConfig(auth: Auth): Promise<void>;
497+
```
498+
499+
### Parameters
500+
501+
| Parameter | Type | Description |
502+
| --- | --- | --- |
503+
| auth | [Auth](./auth.auth.md#auth_interface) | The [Auth](./auth.auth.md#auth_interface) instance. |
504+
505+
<b>Returns:</b>
506+
507+
Promise&lt;void&gt;
508+
509+
### Example
510+
511+
512+
```javascript
513+
initializeRecaptchaConfig(auth);
514+
515+
```
516+
485517
## isSignInWithEmailLink()
486518

487519
Checks if an incoming link is a sign-in with email link suitable for [signInWithEmailLink()](./auth.md#signinwithemaillink)<!-- -->.
@@ -1791,6 +1823,8 @@ AUTH_ERROR_CODES_MAP_DO_NOT_USE_INTERNALLY: {
17911823
readonly WEAK_PASSWORD: "auth/weak-password";
17921824
readonly WEB_STORAGE_UNSUPPORTED: "auth/web-storage-unsupported";
17931825
readonly ALREADY_INITIALIZED: "auth/already-initialized";
1826+
readonly RECAPTCHA_CHECK_FAILED: "auth/recaptcha-check-failed";
1827+
readonly RECAPTCHA_NOT_ENABLED: "auth/recaptcha-not-enabled";
17941828
}
17951829
```
17961830

docs-devsite/auth.recaptchaconfig.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# RecaptchaConfig interface
13+
14+
<b>Signature:</b>
15+
16+
```typescript
17+
export interface RecaptchaConfig
18+
```
19+
20+
## Properties
21+
22+
| Property | Type | Description |
23+
| --- | --- | --- |
24+
| [emailPasswordEnabled](./auth.recaptchaconfig.md#recaptchaconfigemailpasswordenabled) | boolean | The reCAPTCHA enablement status of the [EmailAuthProvider](./auth.emailauthprovider.md#emailauthprovider_class) for the current tenant. |
25+
26+
## RecaptchaConfig.emailPasswordEnabled
27+
28+
The reCAPTCHA enablement status of the [EmailAuthProvider](./auth.emailauthprovider.md#emailauthprovider_class) for the current tenant.
29+
30+
<b>Signature:</b>
31+
32+
```typescript
33+
emailPasswordEnabled: boolean;
34+
```

packages/auth/demo/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ function onSignInAnonymously() {
473473
function onSetTenantID(_event) {
474474
const tenantId = $('#tenant-id').val();
475475
auth.tenantId = tenantId;
476-
if (tenantId === "") {
476+
if (tenantId === '') {
477477
auth.tenantId = null;
478478
}
479479
}

packages/auth/src/api/authentication/email_and_password.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ import chaiAsPromised from 'chai-as-promised';
2121
import { ActionCodeOperation } from '../../model/public_types';
2222
import { FirebaseError } from '@firebase/util';
2323

24-
import { Endpoint, HttpHeader, RecaptchaClientType, RecaptchaVersion } from '../';
24+
import {
25+
Endpoint,
26+
HttpHeader,
27+
RecaptchaClientType,
28+
RecaptchaVersion
29+
} from '../';
2530
import { mockEndpoint } from '../../../test/helpers/api/helper';
2631
import { testAuth, TestAuth } from '../../../test/helpers/mock_auth';
2732
import * as mockFetch from '../../../test/helpers/mock_fetch';
@@ -47,7 +52,7 @@ describe('api/authentication/signInWithPassword', () => {
4752
password: 'my-password',
4853
captchaResponse: 'recaptcha-token',
4954
clientType: RecaptchaClientType.WEB,
50-
recaptchaVersion: RecaptchaVersion.ENTERPRISE,
55+
recaptchaVersion: RecaptchaVersion.ENTERPRISE
5156
};
5257

5358
let auth: TestAuth;
@@ -168,8 +173,8 @@ describe('api/authentication/sendPasswordResetEmail', () => {
168173
169174
captchaResp: 'recaptcha-token',
170175
clientType: RecaptchaClientType.WEB,
171-
recaptchaVersion: RecaptchaVersion.ENTERPRISE,
172-
};
176+
recaptchaVersion: RecaptchaVersion.ENTERPRISE
177+
};
173178

174179
let auth: TestAuth;
175180

@@ -229,7 +234,7 @@ describe('api/authentication/sendSignInLinkToEmail', () => {
229234
230235
captchaResp: 'recaptcha-token',
231236
clientType: RecaptchaClientType.WEB,
232-
recaptchaVersion: RecaptchaVersion.ENTERPRISE,
237+
recaptchaVersion: RecaptchaVersion.ENTERPRISE
233238
};
234239

235240
let auth: TestAuth;

packages/auth/src/api/authentication/recaptcha.test.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ import chaiAsPromised from 'chai-as-promised';
2020

2121
import { FirebaseError } from '@firebase/util';
2222

23-
import { Endpoint, HttpHeader, RecaptchaClientType, RecaptchaVersion } from '../';
24-
import { mockEndpoint, mockEndpointWithParams } from '../../../test/helpers/api/helper';
23+
import {
24+
Endpoint,
25+
HttpHeader,
26+
RecaptchaClientType,
27+
RecaptchaVersion
28+
} from '../';
29+
import {
30+
mockEndpoint,
31+
mockEndpointWithParams
32+
} from '../../../test/helpers/api/helper';
2533
import { testAuth, TestAuth } from '../../../test/helpers/mock_auth';
2634
import * as mockFetch from '../../../test/helpers/mock_fetch';
2735
import { ServerError } from '../errors';
28-
import { getRecaptchaParams, getRecaptchaConfig, } from './recaptcha';
36+
import { getRecaptchaParams, getRecaptchaConfig } from './recaptcha';
2937

3038
use(chaiAsPromised);
3139

@@ -84,7 +92,7 @@ describe('api/authentication/getRecaptchaParams', () => {
8492
describe('api/authentication/getRecaptchaConfig', () => {
8593
const request = {
8694
clientType: RecaptchaClientType.WEB,
87-
recaptchaVersion: RecaptchaVersion.ENTERPRISE,
95+
recaptchaVersion: RecaptchaVersion.ENTERPRISE
8896
};
8997

9098
let auth: TestAuth;
@@ -97,9 +105,13 @@ describe('api/authentication/getRecaptchaConfig', () => {
97105
afterEach(mockFetch.tearDown);
98106

99107
it('should GET to the correct endpoint', async () => {
100-
const mock = mockEndpointWithParams(Endpoint.GET_RECAPTCHA_CONFIG, request, {
101-
recaptchaKey: 'site-key'
102-
});
108+
const mock = mockEndpointWithParams(
109+
Endpoint.GET_RECAPTCHA_CONFIG,
110+
request,
111+
{
112+
recaptchaKey: 'site-key'
113+
}
114+
);
103115

104116
const response = await getRecaptchaConfig(auth, request);
105117
expect(response.recaptchaKey).to.eq('site-key');
@@ -119,7 +131,7 @@ describe('api/authentication/getRecaptchaConfig', () => {
119131
{
120132
error: {
121133
code: 400,
122-
message: ServerError.UNAUTHORIZED_DOMAIN,
134+
message: ServerError.UNAUTHORIZED_DOMAIN
123135
}
124136
},
125137
400
@@ -130,4 +142,4 @@ describe('api/authentication/getRecaptchaConfig', () => {
130142
'auth/unauthorized-continue-uri'
131143
);
132144
});
133-
});
145+
});

packages/auth/src/api/authentication/recaptcha.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { Endpoint, HttpMethod, RecaptchaClientType, RecaptchaVersion, _performApiRequest, _addTidIfNecessary } from '../index';
18+
import {
19+
Endpoint,
20+
HttpMethod,
21+
RecaptchaClientType,
22+
RecaptchaVersion,
23+
_performApiRequest,
24+
_addTidIfNecessary
25+
} from '../index';
1926
import { Auth, RecaptchaConfig } from '../../model/public_types';
2027

2128
interface GetRecaptchaParamResponse {
@@ -42,13 +49,17 @@ interface GetRecaptchaConfigRequest {
4249

4350
interface GetRecaptchaConfigResponse {
4451
recaptchaKey?: string;
45-
recaptchaConfig?: RecaptchaConfig
52+
recaptchaConfig?: RecaptchaConfig;
4653
}
4754

48-
export async function getRecaptchaConfig(auth: Auth,
55+
export async function getRecaptchaConfig(
56+
auth: Auth,
4957
request: GetRecaptchaConfigRequest
5058
): Promise<GetRecaptchaConfigResponse> {
51-
return _performApiRequest<GetRecaptchaConfigRequest, GetRecaptchaConfigResponse>(
59+
return _performApiRequest<
60+
GetRecaptchaConfigRequest,
61+
GetRecaptchaConfigResponse
62+
>(
5263
auth,
5364
HttpMethod.GET,
5465
Endpoint.GET_RECAPTCHA_CONFIG,

packages/auth/src/api/authentication/sign_up.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import chaiAsPromised from 'chai-as-promised';
2020

2121
import { FirebaseError } from '@firebase/util';
2222

23-
import { Endpoint, HttpHeader, RecaptchaClientType, RecaptchaVersion } from '../';
23+
import {
24+
Endpoint,
25+
HttpHeader,
26+
RecaptchaClientType,
27+
RecaptchaVersion
28+
} from '../';
2429
import { mockEndpoint } from '../../../test/helpers/api/helper';
2530
import { testAuth, TestAuth } from '../../../test/helpers/mock_auth';
2631
import * as mockFetch from '../../../test/helpers/mock_fetch';
@@ -36,8 +41,8 @@ describe('api/authentication/signUp', () => {
3641
password: 'my-password',
3742
captchaResponse: 'recaptcha-token',
3843
clientType: RecaptchaClientType.WEB,
39-
recaptchaVersion: RecaptchaVersion.ENTERPRISE,
40-
};
44+
recaptchaVersion: RecaptchaVersion.ENTERPRISE
45+
};
4146

4247
let auth: TestAuth;
4348

packages/auth/src/api/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,23 @@ export const enum Endpoint {
6666
FINALIZE_MFA_SIGN_IN = '/v2/accounts/mfaSignIn:finalize',
6767
WITHDRAW_MFA = '/v2/accounts/mfaEnrollment:withdraw',
6868
GET_PROJECT_CONFIG = '/v1/projects',
69-
GET_RECAPTCHA_CONFIG = '/v2/recaptchaConfig',
69+
GET_RECAPTCHA_CONFIG = '/v2/recaptchaConfig'
7070
}
7171

7272
export const enum RecaptchaClientType {
7373
WEB = 'CLIENT_TYPE_WEB',
7474
ANDROID = 'CLIENT_TYPE_ANDROID',
75-
IOS = 'CLIENT_TYPE_IOS',
75+
IOS = 'CLIENT_TYPE_IOS'
7676
}
7777

7878
export const enum RecaptchaVersion {
79-
ENTERPRISE = 'RECAPTCHA_ENTERPRISE',
79+
ENTERPRISE = 'RECAPTCHA_ENTERPRISE'
8080
}
8181

8282
export const enum RecaptchaActionName {
8383
SIGN_IN_WITH_PASSWORD = 'signInWithPassword',
8484
GET_OOB_CODE = 'getOobCode',
85-
SIGN_UP_PASSWORD = 'signUpPassword',
85+
SIGN_UP_PASSWORD = 'signUpPassword'
8686
}
8787

8888
export const DEFAULT_API_TIMEOUT_MS = new Delay(30_000, 60_000);

0 commit comments

Comments
 (0)