UNPKG

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