1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/fire/auth'), require('@angular/router'), require('firebase/app'), require('@angular/fire')) :
|
3 | typeof define === 'function' && define.amd ? define('@angular/fire/auth-guard', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/fire/auth', '@angular/router', 'firebase/app', '@angular/fire'], factory) :
|
4 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.angular = global.angular || {}, global.angular.fire = global.angular.fire || {}, global.angular.fire['auth-guard'] = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.angular.fire.auth, global.ng.router, global.firebase, global.angular.fire));
|
5 | }(this, (function (exports, i0, rxjs, operators, i2, i1, app, fire) { 'use strict';
|
6 |
|
7 | function _interopNamespace(e) {
|
8 | if (e && e.__esModule) return e;
|
9 | var n = Object.create(null);
|
10 | if (e) {
|
11 | Object.keys(e).forEach(function (k) {
|
12 | if (k !== 'default') {
|
13 | var d = Object.getOwnPropertyDescriptor(e, k);
|
14 | Object.defineProperty(n, k, d.get ? d : {
|
15 | enumerable: true,
|
16 | get: function () {
|
17 | return e[k];
|
18 | }
|
19 | });
|
20 | }
|
21 | });
|
22 | }
|
23 | n['default'] = e;
|
24 | return Object.freeze(n);
|
25 | }
|
26 |
|
27 | var i0__namespace = _interopNamespace(i0);
|
28 | var i2__namespace = _interopNamespace(i2);
|
29 | var i1__namespace = _interopNamespace(i1);
|
30 |
|
31 | var loggedIn = operators.map(function (user) { return !!user; });
|
32 | var AuthGuard = (function () {
|
33 | function AuthGuard(router, auth) {
|
34 | var _this = this;
|
35 | this.router = router;
|
36 | this.auth = auth;
|
37 | this.canActivate = function (next, state) {
|
38 | var authPipeFactory = next.data.authGuardPipe || (function () { return loggedIn; });
|
39 | return i2.user(_this.auth).pipe(operators.take(1), authPipeFactory(next, state), operators.map(function (can) {
|
40 | if (typeof can === 'boolean') {
|
41 | return can;
|
42 | }
|
43 | else if (Array.isArray(can)) {
|
44 | return _this.router.createUrlTree(can);
|
45 | }
|
46 | else {
|
47 |
|
48 | return _this.router.parseUrl(can);
|
49 | }
|
50 | }));
|
51 | };
|
52 | }
|
53 | return AuthGuard;
|
54 | }());
|
55 | AuthGuard.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuard, deps: [{ token: i1__namespace.Router }, { token: i2__namespace.Auth }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
56 | AuthGuard.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuard, providedIn: 'any' });
|
57 | i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuard, decorators: [{
|
58 | type: i0.Injectable,
|
59 | args: [{
|
60 | providedIn: 'any'
|
61 | }]
|
62 | }], ctorParameters: function () { return [{ type: i1__namespace.Router }, { type: i2__namespace.Auth }]; } });
|
63 | var canActivate = function (pipe) { return ({
|
64 | canActivate: [AuthGuard], data: { authGuardPipe: pipe }
|
65 | }); };
|
66 | var isNotAnonymous = operators.map(function (user) { return !!user && !user.isAnonymous; });
|
67 | var idTokenResult = operators.switchMap(function (user) { return user ? user.getIdTokenResult() : rxjs.of(null); });
|
68 | var emailVerified = operators.map(function (user) { return !!user && user.emailVerified; });
|
69 | var customClaims = rxjs.pipe(idTokenResult, operators.map(function (idTokenResult) { return idTokenResult ? idTokenResult.claims : []; }));
|
70 | var hasCustomClaim = function (claim) { return rxjs.pipe(customClaims, operators.map(function (claims) { return claims.hasOwnProperty(claim); })); };
|
71 | var redirectUnauthorizedTo = function (redirect) { return rxjs.pipe(loggedIn, operators.map(function (loggedIn) { return loggedIn || redirect; })); };
|
72 | var redirectLoggedInTo = function (redirect) { return rxjs.pipe(loggedIn, operators.map(function (loggedIn) { return loggedIn && redirect || true; })); };
|
73 |
|
74 | var AuthGuardModule = (function () {
|
75 | function AuthGuardModule() {
|
76 | app.registerVersion('angularfire', fire.VERSION.full, 'auth-guard');
|
77 | }
|
78 | return AuthGuardModule;
|
79 | }());
|
80 | AuthGuardModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuardModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
|
81 | AuthGuardModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuardModule });
|
82 | AuthGuardModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuardModule, providers: [AuthGuard] });
|
83 | i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: AuthGuardModule, decorators: [{
|
84 | type: i0.NgModule,
|
85 | args: [{
|
86 | providers: [AuthGuard]
|
87 | }]
|
88 | }], ctorParameters: function () { return []; } });
|
89 |
|
90 | |
91 |
|
92 |
|
93 |
|
94 | exports.AuthGuard = AuthGuard;
|
95 | exports.AuthGuardModule = AuthGuardModule;
|
96 | exports.canActivate = canActivate;
|
97 | exports.customClaims = customClaims;
|
98 | exports.emailVerified = emailVerified;
|
99 | exports.hasCustomClaim = hasCustomClaim;
|
100 | exports.idTokenResult = idTokenResult;
|
101 | exports.isNotAnonymous = isNotAnonymous;
|
102 | exports.loggedIn = loggedIn;
|
103 | exports.redirectLoggedInTo = redirectLoggedInTo;
|
104 | exports.redirectUnauthorizedTo = redirectUnauthorizedTo;
|
105 |
|
106 | Object.defineProperty(exports, '__esModule', { value: true });
|
107 |
|
108 | })));
|
109 |
|