UNPKG

4.78 kBSource Map (JSON)View Raw
1{"version":3,"file":"angular-fire-auth-guard.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":[],"mappings":";;;;;;;;;;MAUa,QAAQ,GAAa,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE;MAKzC,SAAS;IAEpB,YAAoB,MAAc,EAAU,IAAU;QAAlC,WAAM,GAAN,MAAM,CAAQ;QAAU,SAAI,GAAJ,IAAI,CAAM;QAEtD,gBAAW,GAAG,CAAC,IAA4B,EAAE,KAA0B;YACrE,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,aAAkC,KAAK,MAAM,QAAQ,CAAC,CAAC;YACzF,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CACzB,IAAI,CAAC,CAAC,CAAC,EACP,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,EAC5B,GAAG,CAAC,GAAG;gBACL,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;oBAC5B,OAAO,GAAG,CAAC;iBACZ;qBAAM,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;oBAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;iBACvC;qBAAM;;oBAEL,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;iBAClC;aACF,CAAC,CACH,CAAC;SACH,CAAA;KAl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