UNPKG

@iotize/ionic

Version:

Iotize specific building blocks on top of @ionic/angular.

102 lines (95 loc) 4.69 kB
import * as i0 from '@angular/core'; import { Injectable, NgModule } from '@angular/core'; import * as i1 from '@iotize/ionic'; import { LibCommonModule, TaskManagerModule, TaskManagerUiModule } from '@iotize/ionic'; import { Subject, defer } from 'rxjs'; import { map } from 'rxjs/operators'; import { createDebugger } from '@iotize/common/debug'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; const debug = createDebugger('@iotize/ionic:auth'); class DeviceAuthGuard { constructor(tapService) { this.tapService = tapService; this._unauthorizedUser = new Subject(); this.unauthorizedPageAccessEvent = this._unauthorizedUser.asObservable(); } canActivate(route, state) { if (!route.data.username) { return true; } return defer(() => this.tapService.isLoggedInAsUserOrProfileName(route.data.username)).pipe(map((isLoggedAs) => { if (!isLoggedAs) { debug(`User "${this.tapService.sessionStateSnapshot.name}" is not authorized to access "${route.url}" (required profile: "${route.data.username}")`); this._unauthorizedUser.next({ route, state, }); } return isLoggedAs; })); } } /** @nocollapse */ DeviceAuthGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DeviceAuthGuard, deps: [{ token: i1.CurrentDeviceService }], target: i0.ɵɵFactoryTarget.Injectable }); /** @nocollapse */ DeviceAuthGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DeviceAuthGuard, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DeviceAuthGuard, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return [{ type: i1.CurrentDeviceService }]; } }); class TapAuthModule { } /** @nocollapse */ TapAuthModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TapAuthModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); /** @nocollapse */ TapAuthModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: TapAuthModule, imports: [LibCommonModule, FormsModule, ReactiveFormsModule, TaskManagerModule, TaskManagerUiModule] }); /** @nocollapse */ TapAuthModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TapAuthModule, imports: [LibCommonModule, FormsModule, ReactiveFormsModule, TaskManagerModule, TaskManagerUiModule] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TapAuthModule, decorators: [{ type: NgModule, args: [{ declarations: [], providers: [], imports: [ LibCommonModule, FormsModule, ReactiveFormsModule, TaskManagerModule, TaskManagerUiModule, ], }] }] }); class TapAuthService { constructor() { try { this.options = JSON.parse(localStorage.getItem('TapAuthServiceStorage') || '{}'); } catch (err) { this.options = {}; } if (!this.options) { this.options = {}; } } store() { localStorage.setItem('TapAuthServiceStorage', JSON.stringify(this.options)); } } /** @nocollapse */ TapAuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TapAuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); /** @nocollapse */ TapAuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TapAuthService, providedIn: 'root' }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: TapAuthService, decorators: [{ type: Injectable, args: [{ providedIn: 'root', }] }], ctorParameters: function () { return []; } }); /** * Generated bundle index. Do not edit. */ export { DeviceAuthGuard, TapAuthModule, TapAuthService }; //# sourceMappingURL=iotize-ionic-auth.mjs.map