@angular/fire
Version:
Angular + Firebase = ❤️
129 lines (123 loc) • 5.97 kB
JavaScript
import { ɵgetAllInstancesOf as _getAllInstancesOf, ɵgetDefaultInstanceOf as _getDefaultInstanceOf, VERSION, ɵAngularFireSchedulers as _AngularFireSchedulers, ɵzoneWrap as _zoneWrap } from '@angular/fire';
import { timer, from } from 'rxjs';
import { concatMap, distinct } from 'rxjs/operators';
import { isPlatformServer } from '@angular/common';
import * as i0 from '@angular/core';
import { InjectionToken, isDevMode, Optional, PLATFORM_ID, NgModule, makeEnvironmentProviders, NgZone, Injector } from '@angular/core';
import { FirebaseApp, FirebaseApps } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { getLimitedUseToken as getLimitedUseToken$1, getToken as getToken$1, initializeAppCheck as initializeAppCheck$1, onTokenChanged as onTokenChanged$1, setTokenAutoRefreshEnabled as setTokenAutoRefreshEnabled$1 } from 'firebase/app-check';
export * from 'firebase/app-check';
const APP_CHECK_PROVIDER_NAME = 'app-check';
class AppCheck {
constructor(appCheck) {
return appCheck;
}
}
class AppCheckInstances {
constructor() {
return _getAllInstancesOf(APP_CHECK_PROVIDER_NAME);
}
}
const appCheckInstance$ = timer(0, 300).pipe(concatMap(() => from(_getAllInstancesOf(APP_CHECK_PROVIDER_NAME))), distinct());
const PROVIDED_APP_CHECK_INSTANCES = new InjectionToken('angularfire2.app-check-instances');
/**
* Set to `true` in a server-only config to run `provideAppCheck` during server rendering.
* By default App Check is skipped there, and `AppCheck` injects as `null`.
*/
const APP_CHECK_ON_SERVER = new InjectionToken('angularfire2.app-check-on-server', {
providedIn: 'root',
factory: () => false,
});
function defaultAppCheckInstanceFactory(provided, defaultApp) {
// A skipped server render leaves an undefined entry, which ɵgetDefaultInstanceOf cannot read.
const providedAppChecks = provided?.filter((appCheck) => !!appCheck);
const defaultAppCheck = _getDefaultInstanceOf(APP_CHECK_PROVIDER_NAME, providedAppChecks, defaultApp);
return defaultAppCheck && new AppCheck(defaultAppCheck);
}
const LOCALHOSTS = ['localhost', '0.0.0.0', '127.0.0.1'];
const isLocalhost = typeof window !== 'undefined' && LOCALHOSTS.includes(window.location.hostname);
let warnedServerSkip = false;
function appCheckInstanceFactory(fn) {
return (zone, injector, platformId) => {
if (isPlatformServer(platformId) && !injector.get(APP_CHECK_ON_SERVER)) {
if (isDevMode() && !warnedServerSkip) {
warnedServerSkip = true;
console.warn("AngularFire skips App Check during server rendering, so server-side Firebase requests carry no App Check token. To run App Check there, provide APP_CHECK_ON_SERVER as true in your server config. Find more at https://github.com/angular/angularfire/blob/main/docs/app-check.md");
}
return undefined;
}
// Browser dev mode and localhost use the debug token
if (!isPlatformServer(platformId) && (isDevMode() || isLocalhost)) {
globalThis.FIREBASE_APPCHECK_DEBUG_TOKEN ??= true;
}
const appCheck = zone.runOutsideAngular(() => fn(injector));
return new AppCheck(appCheck);
};
}
const APP_CHECK_INSTANCES_PROVIDER = {
provide: AppCheckInstances,
deps: [
[new Optional(), PROVIDED_APP_CHECK_INSTANCES],
]
};
const DEFAULT_APP_CHECK_INSTANCE_PROVIDER = {
provide: AppCheck,
useFactory: defaultAppCheckInstanceFactory,
deps: [
[new Optional(), PROVIDED_APP_CHECK_INSTANCES],
FirebaseApp,
PLATFORM_ID,
]
};
class AppCheckModule {
constructor() {
registerVersion('angularfire', VERSION.full, 'app-check');
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.22", ngImport: i0, type: AppCheckModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.22", ngImport: i0, type: AppCheckModule });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.22", ngImport: i0, type: AppCheckModule, providers: [
DEFAULT_APP_CHECK_INSTANCE_PROVIDER,
APP_CHECK_INSTANCES_PROVIDER,
] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.22", ngImport: i0, type: AppCheckModule, decorators: [{
type: NgModule,
args: [{
providers: [
DEFAULT_APP_CHECK_INSTANCE_PROVIDER,
APP_CHECK_INSTANCES_PROVIDER,
]
}]
}], ctorParameters: () => [] });
function provideAppCheck(fn, ...deps) {
registerVersion('angularfire', VERSION.full, 'app-check');
return makeEnvironmentProviders([
DEFAULT_APP_CHECK_INSTANCE_PROVIDER,
APP_CHECK_INSTANCES_PROVIDER,
{
provide: PROVIDED_APP_CHECK_INSTANCES,
useFactory: appCheckInstanceFactory(fn),
multi: true,
deps: [
NgZone,
Injector,
PLATFORM_ID,
_AngularFireSchedulers,
FirebaseApps,
...deps,
]
}
]);
}
// DO NOT MODIFY, this file is autogenerated by tools/build.ts
const getLimitedUseToken = _zoneWrap(getLimitedUseToken$1, true, 2);
const getToken = _zoneWrap(getToken$1, true);
const initializeAppCheck = _zoneWrap(initializeAppCheck$1, true);
const onTokenChanged = _zoneWrap(onTokenChanged$1, true);
const setTokenAutoRefreshEnabled = _zoneWrap(setTokenAutoRefreshEnabled$1, true);
/**
* Generated bundle index. Do not edit.
*/
export { APP_CHECK_ON_SERVER, AppCheck, AppCheckInstances, AppCheckModule, appCheckInstance$, getLimitedUseToken, getToken, initializeAppCheck, onTokenChanged, provideAppCheck, setTokenAutoRefreshEnabled };
//# sourceMappingURL=angular-fire-app-check.mjs.map