1 | {"version":3,"file":"angular-fire-auth-guard.umd.js","sources":["../../../src/auth-guard/auth-guard.ts","../../../src/auth-guard/auth-guard.module.ts","../../../src/auth-guard/angular-fire-auth-guard.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';\nimport { Observable, of, pipe, UnaryFunction } from 'rxjs';\nimport { map, switchMap, take } from 'rxjs/operators';\nimport { Auth, user } from '@angular/fire/auth';\nimport { User } from 'firebase/auth';\n\nexport type AuthPipeGenerator = (next: ActivatedRouteSnapshot, state: RouterStateSnapshot) => AuthPipe;\nexport type AuthPipe = UnaryFunction<Observable<User|null>, Observable<boolean|string|any[]>>;\n\nexport const loggedIn: AuthPipe = map(user => !!user);\n\n@Injectable({\n providedIn: 'any'\n})\nexport class AuthGuard implements CanActivate {\n\n constructor(private router: Router, private auth: Auth) {}\n\n canActivate = (next: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {\n const authPipeFactory = next.data.authGuardPipe as AuthPipeGenerator || (() => loggedIn);\n return user(this.auth).pipe(\n take(1),\n authPipeFactory(next, state),\n map(can => {\n if (typeof can === 'boolean') {\n return can;\n } else if (Array.isArray(can)) {\n return this.router.createUrlTree(can);\n } else {\n // TODO(EdricChan03): Add tests\n return this.router.parseUrl(can);\n }\n })\n );\n }\n\n}\n\nexport const canActivate = (pipe: AuthPipeGenerator) => ({\n canActivate: [ AuthGuard ], data: { authGuardPipe: pipe }\n});\n\nexport const isNotAnonymous: AuthPipe = map(user => !!user && !user.isAnonymous);\nexport const idTokenResult = switchMap((user: User|null) => user ? user.getIdTokenResult() : of(null));\nexport const emailVerified: AuthPipe = map(user => !!user && user.emailVerified);\nexport const customClaims = pipe(idTokenResult, map(idTokenResult => idTokenResult ? idTokenResult.claims : []));\nexport const hasCustomClaim: (claim: string) => AuthPipe =\n (claim) => pipe(customClaims, map(claims => claims.hasOwnProperty(claim)));\nexport const redirectUnauthorizedTo: (redirect: string|any[]) => AuthPipe =\n (redirect) => pipe(loggedIn, map(loggedIn => loggedIn || redirect));\nexport const redirectLoggedInTo: (redirect: string|any[]) => AuthPipe =\n (redirect) => pipe(loggedIn, map(loggedIn => loggedIn && redirect || true));\n","import { NgModule } from '@angular/core';\nimport { AuthGuard } from './auth-guard';\nimport { registerVersion } from 'firebase/app';\nimport { VERSION } from '@angular/fire';\n\n@NgModule({\n providers: [ AuthGuard ]\n})\nexport class AuthGuardModule {\n constructor() {\n registerVersion('angularfire', VERSION.full, 'auth-guard');\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["map","user","take","Injectable","switchMap","of","pipe","registerVersion","VERSION","NgModule"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAUa,QAAQ,GAAaA,aAAG,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,CAAC,IAAI,GAAA,EAAE;;QAOpD,mBAAoB,MAAc,EAAU,IAAU;YAAtD,iBAA0D;YAAtC,WAAM,GAAN,MAAM,CAAQ;YAAU,SAAI,GAAJ,IAAI,CAAM;YAEtD,gBAAW,GAAG,UAAC,IAA4B,EAAE,KAA0B;gBACrE,IAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,aAAkC,KAAK,cAAM,OAAA,QAAQ,GAAA,CAAC,CAAC;gBACzF,OAAOC,OAAI,CAAC,KAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CACzBC,cAAI,CAAC,CAAC,CAAC,EACP,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,EAC5BF,aAAG,CAAC,UAAA,GAAG;oBACL,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;wBAC5B,OAAO,GAAG,CAAC;qBACZ;yBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;wBAC7B,OAAO,KAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;qBACvC;yBAAM;;wBAEL,OAAO,KAAI,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