Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
423b3e9
refactor: match AppCheck with firebase-js-sdk
russellwheatley Feb 12, 2026
5435550
refactor: modular should use internal AppCheck type
russellwheatley Feb 12, 2026
2b63dbf
chore: use AppCheckInternal in modular and remove ts-ignore for MODUL…
russellwheatley Feb 12, 2026
bda105b
refactor: namespaced.ts using previous index.d.ts + update modular ap…
russellwheatley Feb 12, 2026
bdeff28
chore: annotate namespaced types as deprecated
russellwheatley Feb 12, 2026
0fd4dcc
chore: update types to unsubscribe
russellwheatley Feb 12, 2026
8698293
refactor: change AppCheckListenerResult to AppCheckTokenResult
russellwheatley Feb 13, 2026
421ea77
fix(ai): use deprecated type so when we remove this will be flagged a…
russellwheatley Feb 13, 2026
2649a8c
chore: use firebase-js-sdk types for app check web
russellwheatley Feb 13, 2026
c277355
fix: remove FirebaseAppCheckTypes export from modular types
russellwheatley Feb 13, 2026
4aa08e7
fix: export FirebaseAppCheckTypes from index and fix type-tests
russellwheatley Feb 13, 2026
f5de6b8
refactor: remove statics from modular and export CustomProvider from …
russellwheatley Feb 13, 2026
98e0ac9
refactor: allow passing in providerOptions into constructor
russellwheatley Feb 16, 2026
76ab3a8
refactor: move Custom Provider and ReactNativeFirebaseAppCheckProvide…
russellwheatley Feb 16, 2026
2b8d3cf
refactor: modular types to match firebase-js-sdk as close as possible
russellwheatley Feb 16, 2026
2f44732
chore: ensure native module is types for app check
russellwheatley Feb 16, 2026
283b7ce
chore: annotate public types and rm deprecated types from internal
russellwheatley Feb 16, 2026
572df70
refactor: use class ReactNativeFirebaseAppCheckProvider as type
russellwheatley Feb 16, 2026
a2dbafb
chore: get common types internally
russellwheatley Feb 16, 2026
540ee78
fix: export FirebaseAppCheckTypes as type
russellwheatley Feb 16, 2026
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
12 changes: 5 additions & 7 deletions packages/ai/lib/models/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { FirebaseAppCheckTypes } from '@react-native-firebase/app-check';
import { AIError } from '../errors';
import { AI, AIErrorCode } from '../public-types';
import { AIService } from '../service';
Expand Down Expand Up @@ -52,12 +52,10 @@ export function initApiSettings(ai: AI): ApiSettings {
backend: ai.backend,
};

if ((ai as AIService).appCheck) {
if (ai.options?.useLimitedUseAppCheckTokens) {
apiSettings.getAppCheckToken = () => (ai as AIService).appCheck!.getLimitedUseToken();
} else {
apiSettings.getAppCheckToken = () => (ai as AIService).appCheck!.getToken();
}
const appCheck = ai.appCheck as FirebaseAppCheckTypes.Module;
if (appCheck) {
apiSettings.getAppCheckToken = () =>
ai.options?.useLimitedUseAppCheckTokens ? appCheck.getLimitedUseToken() : appCheck.getToken();
}

if ((ai as AIService).auth?.currentUser) {
Expand Down
21 changes: 0 additions & 21 deletions packages/app-check/lib/ReactNativeFirebaseAppCheckProvider.ts

This file was deleted.

23 changes: 2 additions & 21 deletions packages/app-check/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,12 @@
*/

// Export types from types/appcheck
export type {
AppCheckProvider,
CustomProviderOptions,
AppCheckOptions,
AppCheckToken,
AppCheckTokenResult,
AppCheckListenerResult,
PartialObserver,
Observer,
NextFn,
ErrorFn,
CompleteFn,
Unsubscribe,
ReactNativeFirebaseAppCheckProviderOptions,
ReactNativeFirebaseAppCheckProviderWebOptions,
ReactNativeFirebaseAppCheckProviderAppleOptions,
ReactNativeFirebaseAppCheckProviderAndroidOptions,
ReactNativeFirebaseAppCheckProvider,
AppCheck,
FirebaseAppCheckTypes,
} from './types/appcheck';
export type * from './types/appcheck';

// Export modular API functions
export * from './modular';

// Export namespaced API
export type { FirebaseAppCheckTypes } from './types/namespaced';
export * from './namespaced';
export { default } from './namespaced';
76 changes: 38 additions & 38 deletions packages/app-check/lib/modular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
*
*/

import { getApp, type ReactNativeFirebase } from '@react-native-firebase/app';
import { getApp, type FirebaseApp } from '@react-native-firebase/app';
import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
import ReactNativeFirebaseAppCheckProvider from './ReactNativeFirebaseAppCheckProvider';

import type {
AppCheck,
AppCheckOptions,
AppCheckTokenResult,
PartialObserver,
Unsubscribe,
AppCheckListenerResult,
} from './types/appcheck';
import type { AppCheckInternal } from './types/internal';

export { CustomProvider, ReactNativeFirebaseAppCheckProvider } from './providers';

type WithModularDeprecationArg<F> = F extends (...args: infer P) => infer R
? (...args: [...P, typeof MODULAR_DEPRECATION_ARG]) => R
: never;

/**
* Activate App Check for the given app. Can be called only once per app.
Expand All @@ -35,20 +40,16 @@ import type {
* @returns Promise<AppCheck>
*/
export async function initializeAppCheck(
app?: ReactNativeFirebase.FirebaseApp,
app?: FirebaseApp,
options?: AppCheckOptions,
): Promise<AppCheck> {
if (app) {
const appInstance = getApp(app.name) as ReactNativeFirebase.FirebaseApp;
const appCheck = appInstance.appCheck();
// @ts-ignore - Extra arg used by deprecation proxy to detect modular calls
await appCheck.initializeAppCheck.call(appCheck, options, MODULAR_DEPRECATION_ARG);
return appCheck;
}
const appInstance = getApp() as ReactNativeFirebase.FirebaseApp;
const appInstance = app ? (getApp(app.name) as FirebaseApp) : (getApp() as FirebaseApp);
const appCheck = appInstance.appCheck();
// @ts-ignore - Extra arg used by deprecation proxy to detect modular calls
await appCheck.initializeAppCheck.call(appCheck, options, MODULAR_DEPRECATION_ARG);
await (
(appCheck as AppCheckInternal).initializeAppCheck as WithModularDeprecationArg<
AppCheckInternal['initializeAppCheck']
>
).call(appCheck, options as AppCheckOptions, MODULAR_DEPRECATION_ARG);
return appCheck;
}

Expand All @@ -63,12 +64,11 @@ export function getToken(
appCheckInstance: AppCheck,
forceRefresh?: boolean,
): Promise<AppCheckTokenResult> {
return appCheckInstance.getToken.call(
appCheckInstance,
forceRefresh,
// @ts-ignore - Extra arg used by deprecation proxy to detect modular calls
MODULAR_DEPRECATION_ARG,
) as Promise<AppCheckTokenResult>;
return (
(appCheckInstance as AppCheckInternal).getToken as WithModularDeprecationArg<
AppCheckInternal['getToken']
>
).call(appCheckInstance, forceRefresh, MODULAR_DEPRECATION_ARG) as Promise<AppCheckTokenResult>;
}

/**
Expand All @@ -78,11 +78,11 @@ export function getToken(
* @returns Promise<AppCheckTokenResult>
*/
export function getLimitedUseToken(appCheckInstance: AppCheck): Promise<AppCheckTokenResult> {
return appCheckInstance.getLimitedUseToken.call(
appCheckInstance,
// @ts-ignore - Extra arg used by deprecation proxy to detect modular calls
MODULAR_DEPRECATION_ARG,
) as Promise<AppCheckTokenResult>;
return (
(appCheckInstance as AppCheckInternal).getLimitedUseToken as WithModularDeprecationArg<
AppCheckInternal['getLimitedUseToken']
>
).call(appCheckInstance, MODULAR_DEPRECATION_ARG) as Promise<AppCheckTokenResult>;
}

/**
Expand All @@ -94,12 +94,11 @@ export function setTokenAutoRefreshEnabled(
appCheckInstance: AppCheck,
isAutoRefreshEnabled: boolean,
): void {
appCheckInstance.setTokenAutoRefreshEnabled.call(
appCheckInstance,
isAutoRefreshEnabled,
// @ts-ignore - Extra arg used by deprecation proxy to detect modular calls
MODULAR_DEPRECATION_ARG,
);
(
(appCheckInstance as AppCheckInternal).setTokenAutoRefreshEnabled as WithModularDeprecationArg<
AppCheckInternal['setTokenAutoRefreshEnabled']
>
).call(appCheckInstance, isAutoRefreshEnabled, MODULAR_DEPRECATION_ARG);
}

/**
Expand All @@ -114,7 +113,7 @@ export function setTokenAutoRefreshEnabled(
*/
export function onTokenChanged(
appCheckInstance: AppCheck,
listener: PartialObserver<AppCheckTokenResult>,
observer: PartialObserver<AppCheckTokenResult>,
): Unsubscribe;

/**
Expand All @@ -131,7 +130,7 @@ export function onTokenChanged(
*/
export function onTokenChanged(
appCheckInstance: AppCheck,
onNext: (tokenResult: AppCheckListenerResult) => void,
onNext: (tokenResult: AppCheckTokenResult) => void,
onError?: (error: Error) => void,
onCompletion?: () => void,
): Unsubscribe;
Expand All @@ -140,18 +139,19 @@ export function onTokenChanged(
appCheckInstance: AppCheck,
onNextOrObserver:
| PartialObserver<AppCheckTokenResult>
| ((tokenResult: AppCheckListenerResult) => void),
| ((tokenResult: AppCheckTokenResult) => void),
onError?: (error: Error) => void,
onCompletion?: () => void,
): Unsubscribe {
return appCheckInstance.onTokenChanged.call(
return (
(appCheckInstance as AppCheckInternal).onTokenChanged as WithModularDeprecationArg<
AppCheckInternal['onTokenChanged']
>
).call(
appCheckInstance,
onNextOrObserver,
onError,
onCompletion,
// @ts-ignore - Extra arg used by deprecation proxy to detect modular calls
MODULAR_DEPRECATION_ARG,
) as Unsubscribe;
}

export { ReactNativeFirebaseAppCheckProvider };
53 changes: 17 additions & 36 deletions packages/app-check/lib/namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
isIOS,
isString,
isObject,
isFunction,
isUndefined,
isOther,
parseListenerOrObserver,
Expand All @@ -32,45 +31,24 @@ import {
} from '@react-native-firebase/app/dist/module/internal';
import type { ModuleConfig } from '@react-native-firebase/app/dist/module/internal';
import { Platform } from 'react-native';
import ReactNativeFirebaseAppCheckProvider from './ReactNativeFirebaseAppCheckProvider';
import { setReactNativeModule } from '@react-native-firebase/app/dist/module/internal/nativeModule';
import fallBackModule from './web/RNFBAppCheckModule';
import { version } from './version';
import type {
CustomProviderOptions,
AppCheckOptions,
AppCheckProvider,
AppCheckTokenResult,
AppCheckOptions,
AppCheckListenerResult,
PartialObserver,
AppCheck,
AppCheckStatics,
ProviderWithOptions,
} from './types/appcheck';
import type { ProviderWithOptions } from './types/internal';
import type { FirebaseAppCheckTypes } from './types/namespaced';
import type { ReactNativeFirebase } from '@react-native-firebase/app';
import { CustomProvider, ReactNativeFirebaseAppCheckProvider } from './providers';

const namespace = 'appCheck';

const nativeModuleName = 'RNFBAppCheckModule';

export class CustomProvider implements AppCheckProvider {
private _customProviderOptions: CustomProviderOptions;

constructor(_customProviderOptions: CustomProviderOptions) {
if (!isObject(_customProviderOptions)) {
throw new Error('Invalid configuration: no provider options defined.');
}
if (!isFunction(_customProviderOptions.getToken)) {
throw new Error('Invalid configuration: no getToken function defined.');
}
this._customProviderOptions = _customProviderOptions;
}

async getToken() {
return this._customProviderOptions.getToken();
}
}

const statics = {
CustomProvider,
};
Expand All @@ -89,7 +67,7 @@ function hasProviderOptions(
);
}

class FirebaseAppCheckModule extends FirebaseModule {
class FirebaseAppCheckModule extends FirebaseModule<typeof nativeModuleName> {
_listenerCount: number;

constructor(
Expand Down Expand Up @@ -226,8 +204,8 @@ class FirebaseAppCheckModule extends FirebaseModule {

onTokenChanged(
onNextOrObserver:
| PartialObserver<AppCheckListenerResult>
| ((tokenResult: AppCheckListenerResult) => void),
| PartialObserver<FirebaseAppCheckTypes.AppCheckListenerResult>
| ((tokenResult: FirebaseAppCheckTypes.AppCheckListenerResult) => void),
_onError?: (error: Error) => void,
_onCompletion?: () => void,
): () => void {
Expand All @@ -239,8 +217,8 @@ class FirebaseAppCheckModule extends FirebaseModule {
}
const nextFn = parseListenerOrObserver(
onNextOrObserver as
| ((value: AppCheckListenerResult) => void)
| { next: (value: AppCheckListenerResult) => void },
| ((value: FirebaseAppCheckTypes.AppCheckListenerResult) => void)
| { next: (value: FirebaseAppCheckTypes.AppCheckListenerResult) => void },
);
// let errorFn = function () { };
// if (onNextOrObserver.error != null) {
Expand Down Expand Up @@ -278,10 +256,13 @@ const appCheckNamespace = createModuleNamespace({
});

type AppCheckNamespace = ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
AppCheck,
AppCheckStatics
FirebaseAppCheckTypes.Module,
FirebaseAppCheckTypes.Statics
> & {
appCheck: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<AppCheck, AppCheckStatics>;
appCheck: ReactNativeFirebase.FirebaseModuleWithStaticsAndApp<
FirebaseAppCheckTypes.Module,
FirebaseAppCheckTypes.Statics
>;
firebase: ReactNativeFirebase.Module;
app(name?: string): ReactNativeFirebase.FirebaseApp;
};
Expand All @@ -296,8 +277,8 @@ export default appCheckNamespace as unknown as AppCheckNamespace;
export const firebase =
getFirebaseRoot() as unknown as ReactNativeFirebase.FirebaseNamespacedExport<
'appCheck',
AppCheck,
AppCheckStatics,
FirebaseAppCheckTypes.Module,
FirebaseAppCheckTypes.Statics,
false
>;

Expand Down
49 changes: 49 additions & 0 deletions packages/app-check/lib/providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type {
AppCheckProvider,
AppCheckToken,
CustomProviderOptions,
ReactNativeFirebaseAppCheckProviderOptionsMap as ProviderOptions,
} from './types/appcheck';
import { isFunction, isObject } from '@react-native-firebase/app/dist/module/common';

/**
* @public Use this to configure providers for android, iOS and "other" platforms.
*/
export class ReactNativeFirebaseAppCheckProvider implements AppCheckProvider {
providerOptions?: ProviderOptions;

constructor(options?: ProviderOptions) {
this.providerOptions = options;
}

configure(options: ProviderOptions): void {
this.providerOptions = options;
}

async getToken(): Promise<AppCheckToken> {
// This is a placeholder - the actual implementation is handled by the native modules
// This method exists to satisfy the AppCheckProvider interface
throw new Error('getToken() must be called after configure() and is handled by native modules');
}
}

/**
* @public Use this to configure a Custom Provider on "other" platform. This will not work on iOS and android.
*/
export class CustomProvider implements AppCheckProvider {
private _customProviderOptions: CustomProviderOptions;

constructor(_customProviderOptions: CustomProviderOptions) {
if (!isObject(_customProviderOptions)) {
throw new Error('Invalid configuration: no provider options defined.');
}
if (!isFunction(_customProviderOptions.getToken)) {
throw new Error('Invalid configuration: no getToken function defined.');
}
this._customProviderOptions = _customProviderOptions;
}

async getToken() {
return this._customProviderOptions.getToken();
}
}
Loading
Loading