UNPKG

5.69 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('@angular/fire/auth')) :
3 typeof define === 'function' && define.amd ? define('@angular/fire/auth-guard', ['exports', '@angular/core', '@angular/router', 'rxjs', 'rxjs/operators', '@angular/fire/auth'], 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.ng.router, global.rxjs, global.rxjs.operators, global.angular.fire.auth));
5}(this, (function (exports, i0, i1, rxjs, operators, i2) { '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 = /*#__PURE__*/_interopNamespace(i0);
28 var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
29 var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
30
31 var ɵ0 = function (user) { return !!user; };
32 var loggedIn = operators.map(ɵ0);
33 var AngularFireAuthGuard = /** @class */ (function () {
34 function AngularFireAuthGuard(router, auth) {
35 var _this = this;
36 this.router = router;
37 this.auth = auth;
38 this.canActivate = function (next, state) {
39 var authPipeFactory = next.data.authGuardPipe || (function () { return loggedIn; });
40 return _this.auth.user.pipe(operators.take(1), authPipeFactory(next, state), operators.map(function (can) {
41 if (typeof can === 'boolean') {
42 return can;
43 }
44 else if (Array.isArray(can)) {
45 return _this.router.createUrlTree(can);
46 }
47 else {
48 // TODO(EdricChan03): Add tests
49 return _this.router.parseUrl(can);
50 }
51 }));
52 };
53 }
54 return AngularFireAuthGuard;
55 }());
56 /** @nocollapse */ AngularFireAuthGuard.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AngularFireAuthGuard_Factory() { return new AngularFireAuthGuard(i0__namespace.ɵɵinject(i1__namespace.Router), i0__namespace.ɵɵinject(i2__namespace.AngularFireAuth)); }, token: AngularFireAuthGuard, providedIn: "any" });
57 AngularFireAuthGuard.decorators = [
58 { type: i0.Injectable, args: [{
59 providedIn: 'any'
60 },] }
61 ];
62 /** @nocollapse */
63 AngularFireAuthGuard.ctorParameters = function () { return [
64 { type: i1.Router },
65 { type: i2.AngularFireAuth }
66 ]; };
67 var canActivate = function (pipe) { return ({
68 canActivate: [AngularFireAuthGuard], data: { authGuardPipe: pipe }
69 }); };
70 var ɵ1 = function (user) { return !!user && !user.isAnonymous; };
71 var isNotAnonymous = operators.map(ɵ1);
72 var ɵ2 = function (user) { return user ? user.getIdTokenResult() : rxjs.of(null); };
73 var idTokenResult = operators.switchMap(ɵ2);
74 var ɵ3 = function (user) { return !!user && user.emailVerified; };
75 var emailVerified = operators.map(ɵ3);
76 var ɵ4 = function (idTokenResult) { return idTokenResult ? idTokenResult.claims : []; };
77 var customClaims = rxjs.pipe(idTokenResult, operators.map(ɵ4));
78 var hasCustomClaim = function (claim) { return rxjs.pipe(customClaims, operators.map(function (claims) { return claims.hasOwnProperty(claim); })); };
79 var redirectUnauthorizedTo = function (redirect) { return rxjs.pipe(loggedIn, operators.map(function (loggedIn) { return loggedIn || redirect; })); };
80 var redirectLoggedInTo = function (redirect) { return rxjs.pipe(loggedIn, operators.map(function (loggedIn) { return loggedIn && redirect || true; })); };
81
82 var AngularFireAuthGuardModule = /** @class */ (function () {
83 function AngularFireAuthGuardModule() {
84 }
85 return AngularFireAuthGuardModule;
86 }());
87 AngularFireAuthGuardModule.decorators = [
88 { type: i0.NgModule, args: [{
89 providers: [AngularFireAuthGuard]
90 },] }
91 ];
92
93 /**
94 * Generated bundle index. Do not edit.
95 */
96
97 exports.AngularFireAuthGuard = AngularFireAuthGuard;
98 exports.AngularFireAuthGuardModule = AngularFireAuthGuardModule;
99 exports.canActivate = canActivate;
100 exports.customClaims = customClaims;
101 exports.emailVerified = emailVerified;
102 exports.hasCustomClaim = hasCustomClaim;
103 exports.idTokenResult = idTokenResult;
104 exports.isNotAnonymous = isNotAnonymous;
105 exports.loggedIn = loggedIn;
106 exports.redirectLoggedInTo = redirectLoggedInTo;
107 exports.redirectUnauthorizedTo = redirectUnauthorizedTo;
108 exports.ɵ0 = ɵ0;
109 exports.ɵ1 = ɵ1;
110 exports.ɵ2 = ɵ2;
111 exports.ɵ3 = ɵ3;
112 exports.ɵ4 = ɵ4;
113
114 Object.defineProperty(exports, '__esModule', { value: true });
115
116})));
117//# sourceMappingURL=angular-fire-auth-guard.umd.js.map