UNPKG

@nativescript/firebase-app-check-debug

Version:
93 lines 2.59 kB
import { firebase, FirebaseApp, FirebaseError } from '@nativescript/firebase-core'; let defaultAppCheck; const fb = firebase(); Object.defineProperty(fb, 'appCheck', { value: (app) => { if (!app) { if (!defaultAppCheck) { defaultAppCheck = new AppCheck(); } return defaultAppCheck; } return new AppCheck(app); }, writable: false, }); export class AppCheckToken { static fromNative(token) { if (token instanceof FIRAppCheckToken) { const t = new AppCheckToken(); t._native = token; return t; } return null; } get native() { return this._native; } get ios() { return this.native; } get token() { return this.native?.token; } get expireTimeMillis() { return this.native?.expirationDate?.getTime?.(); } } let provider; export class AppCheck { constructor(app) { if (app?.native) { this._native = FIRAppCheck.appCheckWithApp(app.native); this._nativeApp = app.native; } else { if (defaultAppCheck) { return defaultAppCheck; } defaultAppCheck = this; this._native = FIRAppCheck.appCheck(); this._nativeApp = FIRApp.defaultApp(); } } static setProviderFactory() { if (!provider) { provider = FIRAppCheckDebugProviderFactory.alloc().init(); } FIRAppCheck.setAppCheckProviderFactory(provider); } activate(isTokenAutoRefreshEnabled) { this.native.isTokenAutoRefreshEnabled = isTokenAutoRefreshEnabled; } getToken(forceRefresh) { return new Promise((resolve, reject) => { this.native.tokenForcingRefreshCompletion(forceRefresh, (token, error) => { if (error) { const err = FirebaseError.fromNative(error); reject(err); } else { resolve(AppCheckToken.fromNative(token)); } }); }); } setTokenAutoRefreshEnabled(enabled) { this.native.isTokenAutoRefreshEnabled = enabled; } get native() { return this._native; } get ios() { return this.native; } get app() { if (!this._app) { // @ts-ignore this._app = FirebaseApp.fromNative(this._nativeApp); } return this._app; } } //# sourceMappingURL=index.ios.js.map