@rxap/authentication 13.0.0-next.0 → 13.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,7 +12,7 @@ export class AuthenticationRoutingService {
|
|
|
12
12
|
this.authenticationService = authenticationService;
|
|
13
13
|
this.deactivated = deactivated;
|
|
14
14
|
if (!deactivated) {
|
|
15
|
-
console.
|
|
15
|
+
console.log('Authentication is enabled');
|
|
16
16
|
this.authenticationService.isAuthenticated$.pipe(tap(isAuthenticated => {
|
|
17
17
|
if (isAuthenticated) {
|
|
18
18
|
return this.router.navigate(['/']);
|
|
@@ -43,4 +43,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.3", ngImpor
|
|
|
43
43
|
type: Inject,
|
|
44
44
|
args: [RXAP_AUTHENTICATION_DEACTIVATED]
|
|
45
45
|
}] }]; } });
|
|
46
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
46
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aGVudGljYXRpb24tcm91dGluZy5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vbGlicy9hdXRoZW50aWNhdGlvbi9zcmMvbGliL2F1dGhlbnRpY2F0aW9uLXJvdXRpbmcuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsVUFBVSxFQUNWLE1BQU0sRUFDTixRQUFRLEVBQ1QsTUFBTSxlQUFlLENBQUM7QUFDdkIsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQ3pDLE9BQU8sRUFBRSx5QkFBeUIsRUFBRSxNQUFNLDBCQUEwQixDQUFDO0FBQ3JFLE9BQU8sRUFBRSwrQkFBK0IsRUFBRSxNQUFNLFVBQVUsQ0FBQztB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WJsZWQnKTtcbiAgICAgIHRoaXMuYXV0aGVudGljYXRpb25TZXJ2aWNlLmlzQXV0aGVudGljYXRlZCQucGlwZShcbiAgICAgICAgdGFwKGlzQXV0aGVudGljYXRlZCA9PiB7XG4gICAgICAgICAgaWYgKGlzQXV0aGVudGljYXRlZCkge1xuICAgICAgICAgICAgcmV0dXJuIHRoaXMucm91dGVyLm5hdmlnYXRlKFsgJy8nIF0pO1xuICAgICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICByZXR1cm4gdGhpcy5yb3V0ZXIubmF2aWdhdGUoWyAnLycsICdhdXRoZW50aWNhdGlvbicsICdsb2dpbicgXSk7XG4gICAgICAgICAgfVxuICAgICAgICB9KVxuICAgICAgKS5zdWJzY3JpYmUoKTtcbiAgICB9XG4gIH1cblxufVxuIl19
|
|
@@ -223,7 +223,7 @@ class AuthenticationRoutingService {
|
|
|
223
223
|
this.authenticationService = authenticationService;
|
|
224
224
|
this.deactivated = deactivated;
|
|
225
225
|
if (!deactivated) {
|
|
226
|
-
console.
|
|
226
|
+
console.log('Authentication is enabled');
|
|
227
227
|
this.authenticationService.isAuthenticated$.pipe(tap(isAuthenticated => {
|
|
228
228
|
if (isAuthenticated) {
|
|
229
229
|
return this.router.navigate(['/']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rxap-authentication.mjs","sources":["../../../../libs/authentication/src/lib/authentication.service.ts","../../../../libs/authentication/src/lib/tokens.ts","../../../../libs/authentication/src/lib/authentication.guard.ts","../../../../libs/authentication/src/lib/register.service.ts","../../../../libs/authentication/src/lib/user.service.ts","../../../../libs/authentication/src/lib/authentication-routing.service.ts","../../../../libs/authentication/src/lib/sign-out.directive.ts","../../../../libs/authentication/src/rxap-authentication.ts"],"sourcesContent":["import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n BehaviorSubject,\n Observable\n} from 'rxjs';\nimport { Router } from '@angular/router';\nimport { tap } from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\nexport const RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY = 'rxap__authenticated';\n\nexport interface IAuthenticationService {\n isAuthenticated$: Observable<boolean | null>;\n\n requestPasswordReset(email: string): Promise<boolean>;\n\n sendPasswordReset(password: string, token: string): Promise<boolean>;\n\n signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean>;\n\n signOut(): Promise<void>;\n\n}\n\nexport function TimeoutPromise<T>(callback: (resolve: (value: T) => void, reject: (error: any) => void) => void, ms: number): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n\n setTimeout(() => {\n callback(resolve, reject);\n }, ms);\n\n });\n}\n\nexport function TimeoutResolve<T>(value: T, ms: number): Promise<T> {\n return new Promise(resolve => {\n\n setTimeout(() => {\n resolve(value);\n }, ms);\n\n });\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RxapAuthenticationService implements IAuthenticationService {\n\n public isAuthenticated$ = new BehaviorSubject<boolean | null>(null);\n\n constructor() {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated().then(isAuthenticated => this.isAuthenticated$.next(isAuthenticated));\n }\n\n public requestPasswordReset(email: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(email !== 'fail@fail', 2500);\n }\n\n public sendPasswordReset(password: string, token: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(password !== 'fail', 2500);\n }\n\n public async signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutPromise((resolve, reject) => {\n\n const login = password !== 'fail';\n this.isAuthenticated$.next(login);\n if (login) {\n if (remember) {\n localStorage.setItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY, 'true');\n }\n resolve(login);\n } else {\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n reject(new Error('Login credentials are invalid'));\n }\n\n }, 2500);\n\n }\n\n public async signOut(): Promise<void> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated$.next(false);\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n }\n\n public signInWithProvider(provider: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return Promise.resolve(false);\n }\n\n public isAuthenticated(): Promise<boolean> {\n return TimeoutPromise((resolve) => {\n resolve(localStorage.getItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY) === 'true');\n }, 2500);\n }\n\n}\n","import { InjectionToken } from '@angular/core';\n\nexport const RXAP_AUTHENTICATION_DEACTIVATED = new InjectionToken<boolean>('rxap/authentication/deactivated');\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n CanActivate,\n CanActivateChild,\n ActivatedRouteSnapshot,\n RouterStateSnapshot,\n UrlTree,\n Router\n} from '@angular/router';\nimport { Observable } from 'rxjs';\nimport { RxapAuthenticationService } from './authentication.service';\nimport {\n map,\n first,\n take\n} from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\n@Injectable({ providedIn: 'root' })\nexport class RxapAuthenticationGuard implements CanActivate, CanActivateChild {\n\n public lastUrl: string | null = null;\n\n constructor(\n @Inject(RxapAuthenticationService)\n public authentication: RxapAuthenticationService,\n @Inject(Router)\n public router: Router,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {}\n\n public canActivate(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate', state.url);\n return this.checkAuthStatus(route, state);\n }\n\n public canActivateChild(\n childRoute: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate child', state.url);\n return this.checkAuthStatus(childRoute, state);\n }\n\n private async checkAuthStatus(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n\n if (this.deactivated) {\n return true;\n }\n\n const authenticated = await this.authentication.isAuthenticated();\n\n if (authenticated === null) {\n if (!this.lastUrl || (state.url !== '/' && !state.url.match(/authentication\\/login/))) {\n this.lastUrl = state.url;\n }\n return this.router.createUrlTree([ '/', 'authentication', 'loading' ]);\n }\n if (authenticated) {\n if (this.lastUrl && (state.url/*?*/ === '/' || state.url.match(/authentication\\/login/))) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n } else {\n if (state.url.match(/authentication/)) {\n if (state.url.match(/authentication\\/reset-password/)) {\n return true;\n }\n return this.router.createUrlTree([ '/' ]);\n } else {\n this.lastUrl = null;\n return true;\n }\n }\n } else {\n if (!state.url.match(/^\\/?authentication/)) {\n this.lastUrl = state.url;\n }\n if (state.url.match(/^\\/?authentication/)) {\n if (this.lastUrl && this.lastUrl.match(/^\\/?authentication/)) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n }\n return true;\n } else {\n return this.router.createUrlTree([ '/', 'authentication', 'login' ]);\n }\n }\n\n }\n\n private createUrlTreeToLastUrl(lastUrl: string): UrlTree {\n\n const urlMatch = lastUrl.match(/^([^?#]+)(\\?([^#]+))?(#(.+))?$/);\n\n if (urlMatch) {\n\n let queryParams: Record<string, string> = {};\n\n if (urlMatch[3]) {\n const queryParamsString = urlMatch[ 3 ];\n queryParams = queryParamsString.split('&').map(param => {\n const split = param.split('=');\n return { [ split[ 0 ] ]: split[ 1 ] };\n }).reduce((params, param) => ({ ...params, ...param }), {});\n }\n\n let fragment: string | undefined = undefined;\n\n if (urlMatch[5]) {\n fragment = urlMatch[5];\n }\n\n return this.router.createUrlTree([urlMatch[1]], {\n queryParams,\n fragment,\n });\n\n }\n\n return this.router.createUrlTree([lastUrl]);\n\n }\n\n}\n","import { Injectable } from '@angular/core';\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RegisterService {\n\n constructor() {\n console.warn('The default RegisterService implementation should only be used in a development environment!');\n }\n\n public register(email: string, password: string): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n}\n","import { Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\n\nexport interface UserProfile {\n username: string;\n firstname?: string;\n lastname?: string;\n name?: string;\n email: string;\n photoURL?: string;\n avatarUrl?: string;\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class UserService<User extends UserProfile = UserProfile> {\n\n public user$ = new BehaviorSubject<User | null>(null);\n\n}\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport { Router } from '@angular/router';\nimport { RxapAuthenticationService } from './authentication.service';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\nimport { tap } from 'rxjs/operators';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AuthenticationRoutingService {\n\n constructor(\n @Inject(Router)\n private readonly router: Router,\n @Inject(RxapAuthenticationService)\n private readonly authenticationService: RxapAuthenticationService,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {\n if (!deactivated) {\n console.warn('Authentication is enabled');\n this.authenticationService.isAuthenticated$.pipe(\n tap(isAuthenticated => {\n if (isAuthenticated) {\n return this.router.navigate([ '/' ]);\n } else {\n return this.router.navigate([ '/', 'authentication', 'login' ]);\n }\n })\n ).subscribe();\n }\n }\n\n}\n","import {\n Directive,\n NgModule,\n HostListener,\n EventEmitter,\n Output\n} from '@angular/core';\nimport { RxapAuthenticationService } from './authentication.service';\n\n@Directive({\n selector: '[rxapSignOut]'\n})\nexport class SignOutDirective {\n\n @Output()\n public successful = new EventEmitter<void>();\n\n @Output()\n public failure = new EventEmitter<Error>();\n\n constructor(private readonly auth: RxapAuthenticationService) { }\n\n @HostListener('click')\n public async onClick() {\n try {\n await this.auth.signOut();\n this.successful.emit();\n } catch (e: any) {\n this.failure.emit(e);\n }\n }\n\n}\n\n@NgModule({\n declarations: [ SignOutDirective ],\n exports: [ SignOutDirective ]\n})\nexport class SignOutDirectiveModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAaa,qCAAqC,GAAG,sBAAsB;SAe3D,cAAc,CAAI,QAA6E,EAAE,EAAU;IACzH,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;QAEpC,UAAU,CAAC;YACT,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAC3B,EAAE,EAAE,CAAC,CAAC;KAER,CAAC,CAAC;AACL,CAAC;SAEe,cAAc,CAAI,KAAQ,EAAE,EAAU;IACpD,OAAO,IAAI,OAAO,CAAC,OAAO;QAExB,UAAU,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC;SAChB,EAAE,EAAE,CAAC,CAAC;KAER,CAAC,CAAC;AACL,CAAC;AAGD;MACa,yBAAyB;IAIpC;QAFO,qBAAgB,GAAG,IAAI,eAAe,CAAiB,IAAI,CAAC,CAAC;QAGlE,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;KAC7F;IAEM,oBAAoB,CAAC,KAAa;QACvC,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,OAAO,cAAc,CAAC,KAAK,KAAK,WAAW,EAAE,IAAI,CAAC,CAAC;KACpD;IAEM,iBAAiB,CAAC,QAAgB,EAAE,KAAa;QACtD,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,OAAO,cAAc,CAAC,Q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GzB,+BAA+B;6HAR9B,4BAA4B,cAF3B,MAAM;2FAEP,4BAA4B;kBAHxC,UAAU;mBAAC;oBACV,UAAU,EAAE,MAAM;iBACnB;;;8BAII,MAAM;+BAAC,MAAM;;8BAEb,MAAM;+BAAC,yBAAyB;;8BAEhC,QAAQ;;8BACR,MAAM;+BAAC,+BAA+B;;;;MCT9B,gBAAgB;IAQ3B,YAA6B,IAA+B;QAA/B,SAAI,GAAJ,IAAI,CAA2B;QALrD,eAAU,GAAG,IAAI,YAAY,EAAQ,CAAC;QAGtC,YAAO,GAAG,IAAI,YAAY,EAAS,CAAC;KAEsB;IAGpD,OAAO;;YAClB,IAAI;gBACF,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC1B,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;aACxB;YAAC,OAAO,CAAM,EAAE;gBACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACtB;SACF;KAAA;;6GAlBU,gBAAgB;iGAAhB,gBAAgB;2FAAhB,gBAAgB;kBAH5B,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;iBAC1B;6GAIQ,UAAU;sBADhB,MAAM;gBAIA,OAAO;sBADb,MAAM;gBAMM,OAAO;sBADnB,YAAY;uBAAC,OAAO;;MAgBV,sBAAsB;;mHAAtB,sBAAsB;oHAAtB,sBAAsB,iBA1BtB,gBAAgB,aAAhB,gBAAgB;oHA0BhB,sBAAsB;2FAAtB,sBAAsB;kBAJlC,QAAQ;mBAAC;oBACR,YAAY,EAAE,CAAE,gBAAgB,CAAE;oBAClC,OAAO,EAAO,CAAE,gBAAgB,CAAE;iBACnC;;;ACrCD;;;;;;"}
|
|
1
|
+
{"version":3,"file":"rxap-authentication.mjs","sources":["../../../../libs/authentication/src/lib/authentication.service.ts","../../../../libs/authentication/src/lib/tokens.ts","../../../../libs/authentication/src/lib/authentication.guard.ts","../../../../libs/authentication/src/lib/register.service.ts","../../../../libs/authentication/src/lib/user.service.ts","../../../../libs/authentication/src/lib/authentication-routing.service.ts","../../../../libs/authentication/src/lib/sign-out.directive.ts","../../../../libs/authentication/src/rxap-authentication.ts"],"sourcesContent":["import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n BehaviorSubject,\n Observable\n} from 'rxjs';\nimport { Router } from '@angular/router';\nimport { tap } from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\nexport const RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY = 'rxap__authenticated';\n\nexport interface IAuthenticationService {\n isAuthenticated$: Observable<boolean | null>;\n\n requestPasswordReset(email: string): Promise<boolean>;\n\n sendPasswordReset(password: string, token: string): Promise<boolean>;\n\n signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean>;\n\n signOut(): Promise<void>;\n\n}\n\nexport function TimeoutPromise<T>(callback: (resolve: (value: T) => void, reject: (error: any) => void) => void, ms: number): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n\n setTimeout(() => {\n callback(resolve, reject);\n }, ms);\n\n });\n}\n\nexport function TimeoutResolve<T>(value: T, ms: number): Promise<T> {\n return new Promise(resolve => {\n\n setTimeout(() => {\n resolve(value);\n }, ms);\n\n });\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RxapAuthenticationService implements IAuthenticationService {\n\n public isAuthenticated$ = new BehaviorSubject<boolean | null>(null);\n\n constructor() {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated().then(isAuthenticated => this.isAuthenticated$.next(isAuthenticated));\n }\n\n public requestPasswordReset(email: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(email !== 'fail@fail', 2500);\n }\n\n public sendPasswordReset(password: string, token: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(password !== 'fail', 2500);\n }\n\n public async signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutPromise((resolve, reject) => {\n\n const login = password !== 'fail';\n this.isAuthenticated$.next(login);\n if (login) {\n if (remember) {\n localStorage.setItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY, 'true');\n }\n resolve(login);\n } else {\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n reject(new Error('Login credentials are invalid'));\n }\n\n }, 2500);\n\n }\n\n public async signOut(): Promise<void> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated$.next(false);\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n }\n\n public signInWithProvider(provider: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return Promise.resolve(false);\n }\n\n public isAuthenticated(): Promise<boolean> {\n return TimeoutPromise((resolve) => {\n resolve(localStorage.getItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY) === 'true');\n }, 2500);\n }\n\n}\n","import { InjectionToken } from '@angular/core';\n\nexport const RXAP_AUTHENTICATION_DEACTIVATED = new InjectionToken<boolean>('rxap/authentication/deactivated');\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n CanActivate,\n CanActivateChild,\n ActivatedRouteSnapshot,\n RouterStateSnapshot,\n UrlTree,\n Router\n} from '@angular/router';\nimport { Observable } from 'rxjs';\nimport { RxapAuthenticationService } from './authentication.service';\nimport {\n map,\n first,\n take\n} from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\n@Injectable({ providedIn: 'root' })\nexport class RxapAuthenticationGuard implements CanActivate, CanActivateChild {\n\n public lastUrl: string | null = null;\n\n constructor(\n @Inject(RxapAuthenticationService)\n public authentication: RxapAuthenticationService,\n @Inject(Router)\n public router: Router,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {}\n\n public canActivate(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate', state.url);\n return this.checkAuthStatus(route, state);\n }\n\n public canActivateChild(\n childRoute: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate child', state.url);\n return this.checkAuthStatus(childRoute, state);\n }\n\n private async checkAuthStatus(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n\n if (this.deactivated) {\n return true;\n }\n\n const authenticated = await this.authentication.isAuthenticated();\n\n if (authenticated === null) {\n if (!this.lastUrl || (state.url !== '/' && !state.url.match(/authentication\\/login/))) {\n this.lastUrl = state.url;\n }\n return this.router.createUrlTree([ '/', 'authentication', 'loading' ]);\n }\n if (authenticated) {\n if (this.lastUrl && (state.url/*?*/ === '/' || state.url.match(/authentication\\/login/))) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n } else {\n if (state.url.match(/authentication/)) {\n if (state.url.match(/authentication\\/reset-password/)) {\n return true;\n }\n return this.router.createUrlTree([ '/' ]);\n } else {\n this.lastUrl = null;\n return true;\n }\n }\n } else {\n if (!state.url.match(/^\\/?authentication/)) {\n this.lastUrl = state.url;\n }\n if (state.url.match(/^\\/?authentication/)) {\n if (this.lastUrl && this.lastUrl.match(/^\\/?authentication/)) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n }\n return true;\n } else {\n return this.router.createUrlTree([ '/', 'authentication', 'login' ]);\n }\n }\n\n }\n\n private createUrlTreeToLastUrl(lastUrl: string): UrlTree {\n\n const urlMatch = lastUrl.match(/^([^?#]+)(\\?([^#]+))?(#(.+))?$/);\n\n if (urlMatch) {\n\n let queryParams: Record<string, string> = {};\n\n if (urlMatch[3]) {\n const queryParamsString = urlMatch[ 3 ];\n queryParams = queryParamsString.split('&').map(param => {\n const split = param.split('=');\n return { [ split[ 0 ] ]: split[ 1 ] };\n }).reduce((params, param) => ({ ...params, ...param }), {});\n }\n\n let fragment: string | undefined = undefined;\n\n if (urlMatch[5]) {\n fragment = urlMatch[5];\n }\n\n return this.router.createUrlTree([urlMatch[1]], {\n queryParams,\n fragment,\n });\n\n }\n\n return this.router.createUrlTree([lastUrl]);\n\n }\n\n}\n","import { Injectable } from '@angular/core';\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RegisterService {\n\n constructor() {\n console.warn('The default RegisterService implementation should only be used in a development environment!');\n }\n\n public register(email: string, password: string): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n}\n","import { Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\n\nexport interface UserProfile {\n username: string;\n firstname?: string;\n lastname?: string;\n name?: string;\n email: string;\n photoURL?: string;\n avatarUrl?: string;\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class UserService<User extends UserProfile = UserProfile> {\n\n public user$ = new BehaviorSubject<User | null>(null);\n\n}\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport { Router } from '@angular/router';\nimport { RxapAuthenticationService } from './authentication.service';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\nimport { tap } from 'rxjs/operators';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AuthenticationRoutingService {\n\n constructor(\n @Inject(Router)\n private readonly router: Router,\n @Inject(RxapAuthenticationService)\n private readonly authenticationService: RxapAuthenticationService,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {\n if (!deactivated) {\n console.log('Authentication is enabled');\n this.authenticationService.isAuthenticated$.pipe(\n tap(isAuthenticated => {\n if (isAuthenticated) {\n return this.router.navigate([ '/' ]);\n } else {\n return this.router.navigate([ '/', 'authentication', 'login' ]);\n }\n })\n ).subscribe();\n }\n }\n\n}\n","import {\n Directive,\n NgModule,\n HostListener,\n EventEmitter,\n Output\n} from '@angular/core';\nimport { RxapAuthenticationService } from './authentication.service';\n\n@Directive({\n selector: '[rxapSignOut]'\n})\nexport class SignOutDirective {\n\n @Output()\n public successful = new EventEmitter<void>();\n\n @Output()\n public failure = new EventEmitter<Error>();\n\n constructor(private readonly auth: RxapAuthenticationService) { }\n\n @HostListener('click')\n public async onClick() {\n try {\n await this.auth.signOut();\n this.successful.emit();\n } catch (e: any) {\n this.failure.emit(e);\n }\n }\n\n}\n\n@NgModule({\n declarations: [ SignOutDirective ],\n exports: [ SignOutDirective ]\n})\nexport class SignOutDirectiveModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MAaa,qCAAqC,GAAG,sBAAsB;SAe3D,cAAc,CAAI,QAA6E,EAAE,EAAU;IACzH,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;QAEpC,UAAU,CAAC;YACT,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAC3B,EAAE,EAAE,CAAC,CAAC;KAER,CAAC,CAAC;AACL,CAAC;SAEe,cAAc,CAAI,KAAQ,EAAE,EAAU;IACpD,OAAO,IAAI,OAAO,CAAC,OAAO;QAExB,UAAU,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC;SAChB,EAAE,EAAE,CAAC,CAAC;KAER,CAAC,CAAC;AACL,CAAC;AAGD;MACa,yBAAyB;IAIpC;QAFO,qBAAgB,GAAG,IAAI,eAAe,CAAiB,IAAI,CAAC,CAAC;QAGlE,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;KAC7F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BACR,YAAY,EAAE,CAAE,gBAAgB,CAAE;oBAClC,OAAO,EAAO,CAAE,gBAAgB,CAAE;iBACnC;;;ACrCD;;;;;;"}
|
|
@@ -214,7 +214,7 @@ class AuthenticationRoutingService {
|
|
|
214
214
|
this.authenticationService = authenticationService;
|
|
215
215
|
this.deactivated = deactivated;
|
|
216
216
|
if (!deactivated) {
|
|
217
|
-
console.
|
|
217
|
+
console.log('Authentication is enabled');
|
|
218
218
|
this.authenticationService.isAuthenticated$.pipe(tap(isAuthenticated => {
|
|
219
219
|
if (isAuthenticated) {
|
|
220
220
|
return this.router.navigate(['/']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rxap-authentication.mjs","sources":["../../../../libs/authentication/src/lib/authentication.service.ts","../../../../libs/authentication/src/lib/tokens.ts","../../../../libs/authentication/src/lib/authentication.guard.ts","../../../../libs/authentication/src/lib/register.service.ts","../../../../libs/authentication/src/lib/user.service.ts","../../../../libs/authentication/src/lib/authentication-routing.service.ts","../../../../libs/authentication/src/lib/sign-out.directive.ts","../../../../libs/authentication/src/rxap-authentication.ts"],"sourcesContent":["import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n BehaviorSubject,\n Observable\n} from 'rxjs';\nimport { Router } from '@angular/router';\nimport { tap } from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\nexport const RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY = 'rxap__authenticated';\n\nexport interface IAuthenticationService {\n isAuthenticated$: Observable<boolean | null>;\n\n requestPasswordReset(email: string): Promise<boolean>;\n\n sendPasswordReset(password: string, token: string): Promise<boolean>;\n\n signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean>;\n\n signOut(): Promise<void>;\n\n}\n\nexport function TimeoutPromise<T>(callback: (resolve: (value: T) => void, reject: (error: any) => void) => void, ms: number): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n\n setTimeout(() => {\n callback(resolve, reject);\n }, ms);\n\n });\n}\n\nexport function TimeoutResolve<T>(value: T, ms: number): Promise<T> {\n return new Promise(resolve => {\n\n setTimeout(() => {\n resolve(value);\n }, ms);\n\n });\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RxapAuthenticationService implements IAuthenticationService {\n\n public isAuthenticated$ = new BehaviorSubject<boolean | null>(null);\n\n constructor() {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated().then(isAuthenticated => this.isAuthenticated$.next(isAuthenticated));\n }\n\n public requestPasswordReset(email: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(email !== 'fail@fail', 2500);\n }\n\n public sendPasswordReset(password: string, token: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(password !== 'fail', 2500);\n }\n\n public async signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutPromise((resolve, reject) => {\n\n const login = password !== 'fail';\n this.isAuthenticated$.next(login);\n if (login) {\n if (remember) {\n localStorage.setItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY, 'true');\n }\n resolve(login);\n } else {\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n reject(new Error('Login credentials are invalid'));\n }\n\n }, 2500);\n\n }\n\n public async signOut(): Promise<void> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated$.next(false);\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n }\n\n public signInWithProvider(provider: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return Promise.resolve(false);\n }\n\n public isAuthenticated(): Promise<boolean> {\n return TimeoutPromise((resolve) => {\n resolve(localStorage.getItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY) === 'true');\n }, 2500);\n }\n\n}\n","import { InjectionToken } from '@angular/core';\n\nexport const RXAP_AUTHENTICATION_DEACTIVATED = new InjectionToken<boolean>('rxap/authentication/deactivated');\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n CanActivate,\n CanActivateChild,\n ActivatedRouteSnapshot,\n RouterStateSnapshot,\n UrlTree,\n Router\n} from '@angular/router';\nimport { Observable } from 'rxjs';\nimport { RxapAuthenticationService } from './authentication.service';\nimport {\n map,\n first,\n take\n} from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\n@Injectable({ providedIn: 'root' })\nexport class RxapAuthenticationGuard implements CanActivate, CanActivateChild {\n\n public lastUrl: string | null = null;\n\n constructor(\n @Inject(RxapAuthenticationService)\n public authentication: RxapAuthenticationService,\n @Inject(Router)\n public router: Router,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {}\n\n public canActivate(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate', state.url);\n return this.checkAuthStatus(route, state);\n }\n\n public canActivateChild(\n childRoute: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate child', state.url);\n return this.checkAuthStatus(childRoute, state);\n }\n\n private async checkAuthStatus(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n\n if (this.deactivated) {\n return true;\n }\n\n const authenticated = await this.authentication.isAuthenticated();\n\n if (authenticated === null) {\n if (!this.lastUrl || (state.url !== '/' && !state.url.match(/authentication\\/login/))) {\n this.lastUrl = state.url;\n }\n return this.router.createUrlTree([ '/', 'authentication', 'loading' ]);\n }\n if (authenticated) {\n if (this.lastUrl && (state.url/*?*/ === '/' || state.url.match(/authentication\\/login/))) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n } else {\n if (state.url.match(/authentication/)) {\n if (state.url.match(/authentication\\/reset-password/)) {\n return true;\n }\n return this.router.createUrlTree([ '/' ]);\n } else {\n this.lastUrl = null;\n return true;\n }\n }\n } else {\n if (!state.url.match(/^\\/?authentication/)) {\n this.lastUrl = state.url;\n }\n if (state.url.match(/^\\/?authentication/)) {\n if (this.lastUrl && this.lastUrl.match(/^\\/?authentication/)) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n }\n return true;\n } else {\n return this.router.createUrlTree([ '/', 'authentication', 'login' ]);\n }\n }\n\n }\n\n private createUrlTreeToLastUrl(lastUrl: string): UrlTree {\n\n const urlMatch = lastUrl.match(/^([^?#]+)(\\?([^#]+))?(#(.+))?$/);\n\n if (urlMatch) {\n\n let queryParams: Record<string, string> = {};\n\n if (urlMatch[3]) {\n const queryParamsString = urlMatch[ 3 ];\n queryParams = queryParamsString.split('&').map(param => {\n const split = param.split('=');\n return { [ split[ 0 ] ]: split[ 1 ] };\n }).reduce((params, param) => ({ ...params, ...param }), {});\n }\n\n let fragment: string | undefined = undefined;\n\n if (urlMatch[5]) {\n fragment = urlMatch[5];\n }\n\n return this.router.createUrlTree([urlMatch[1]], {\n queryParams,\n fragment,\n });\n\n }\n\n return this.router.createUrlTree([lastUrl]);\n\n }\n\n}\n","import { Injectable } from '@angular/core';\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RegisterService {\n\n constructor() {\n console.warn('The default RegisterService implementation should only be used in a development environment!');\n }\n\n public register(email: string, password: string): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n}\n","import { Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\n\nexport interface UserProfile {\n username: string;\n firstname?: string;\n lastname?: string;\n name?: string;\n email: string;\n photoURL?: string;\n avatarUrl?: string;\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class UserService<User extends UserProfile = UserProfile> {\n\n public user$ = new BehaviorSubject<User | null>(null);\n\n}\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport { Router } from '@angular/router';\nimport { RxapAuthenticationService } from './authentication.service';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\nimport { tap } from 'rxjs/operators';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AuthenticationRoutingService {\n\n constructor(\n @Inject(Router)\n private readonly router: Router,\n @Inject(RxapAuthenticationService)\n private readonly authenticationService: RxapAuthenticationService,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {\n if (!deactivated) {\n console.warn('Authentication is enabled');\n this.authenticationService.isAuthenticated$.pipe(\n tap(isAuthenticated => {\n if (isAuthenticated) {\n return this.router.navigate([ '/' ]);\n } else {\n return this.router.navigate([ '/', 'authentication', 'login' ]);\n }\n })\n ).subscribe();\n }\n }\n\n}\n","import {\n Directive,\n NgModule,\n HostListener,\n EventEmitter,\n Output\n} from '@angular/core';\nimport { RxapAuthenticationService } from './authentication.service';\n\n@Directive({\n selector: '[rxapSignOut]'\n})\nexport class SignOutDirective {\n\n @Output()\n public successful = new EventEmitter<void>();\n\n @Output()\n public failure = new EventEmitter<Error>();\n\n constructor(private readonly auth: RxapAuthenticationService) { }\n\n @HostListener('click')\n public async onClick() {\n try {\n await this.auth.signOut();\n this.successful.emit();\n } catch (e: any) {\n this.failure.emit(e);\n }\n }\n\n}\n\n@NgModule({\n declarations: [ SignOutDirective ],\n exports: [ SignOutDirective ]\n})\nexport class SignOutDirectiveModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;MAaa,qCAAqC,GAAG,sBAAsB;SAe3D,cAAc,CAAI,QAA6E,EAAE,EAAU;IACzH,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;QAEpC,UAA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,IAAI;YACF,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;SACxB;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACtB;KACF;;6GAlBU,gBAAgB;iGAAhB,gBAAgB;2FAAhB,gBAAgB;kBAH5B,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;iBAC1B;6GAIQ,UAAU;sBADhB,MAAM;gBAIA,OAAO;sBADb,MAAM;gBAMM,OAAO;sBADnB,YAAY;uBAAC,OAAO;;MAgBV,sBAAsB;;mHAAtB,sBAAsB;oHAAtB,sBAAsB,iBA1BtB,gBAAgB,aAAhB,gBAAgB;oHA0BhB,sBAAsB;2FAAtB,sBAAsB;kBAJlC,QAAQ;mBAAC;oBACR,YAAY,EAAE,CAAE,gBAAgB,CAAE;oBAClC,OAAO,EAAO,CAAE,gBAAgB,CAAE;iBACnC;;;ACrCD;;;;;;"}
|
|
1
|
+
{"version":3,"file":"rxap-authentication.mjs","sources":["../../../../libs/authentication/src/lib/authentication.service.ts","../../../../libs/authentication/src/lib/tokens.ts","../../../../libs/authentication/src/lib/authentication.guard.ts","../../../../libs/authentication/src/lib/register.service.ts","../../../../libs/authentication/src/lib/user.service.ts","../../../../libs/authentication/src/lib/authentication-routing.service.ts","../../../../libs/authentication/src/lib/sign-out.directive.ts","../../../../libs/authentication/src/rxap-authentication.ts"],"sourcesContent":["import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n BehaviorSubject,\n Observable\n} from 'rxjs';\nimport { Router } from '@angular/router';\nimport { tap } from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\nexport const RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY = 'rxap__authenticated';\n\nexport interface IAuthenticationService {\n isAuthenticated$: Observable<boolean | null>;\n\n requestPasswordReset(email: string): Promise<boolean>;\n\n sendPasswordReset(password: string, token: string): Promise<boolean>;\n\n signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean>;\n\n signOut(): Promise<void>;\n\n}\n\nexport function TimeoutPromise<T>(callback: (resolve: (value: T) => void, reject: (error: any) => void) => void, ms: number): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n\n setTimeout(() => {\n callback(resolve, reject);\n }, ms);\n\n });\n}\n\nexport function TimeoutResolve<T>(value: T, ms: number): Promise<T> {\n return new Promise(resolve => {\n\n setTimeout(() => {\n resolve(value);\n }, ms);\n\n });\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RxapAuthenticationService implements IAuthenticationService {\n\n public isAuthenticated$ = new BehaviorSubject<boolean | null>(null);\n\n constructor() {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated().then(isAuthenticated => this.isAuthenticated$.next(isAuthenticated));\n }\n\n public requestPasswordReset(email: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(email !== 'fail@fail', 2500);\n }\n\n public sendPasswordReset(password: string, token: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutResolve(password !== 'fail', 2500);\n }\n\n public async signInWithEmailAndPassword(email: string, password: string, remember: boolean): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return TimeoutPromise((resolve, reject) => {\n\n const login = password !== 'fail';\n this.isAuthenticated$.next(login);\n if (login) {\n if (remember) {\n localStorage.setItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY, 'true');\n }\n resolve(login);\n } else {\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n reject(new Error('Login credentials are invalid'));\n }\n\n }, 2500);\n\n }\n\n public async signOut(): Promise<void> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n this.isAuthenticated$.next(false);\n localStorage.removeItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY);\n }\n\n public signInWithProvider(provider: string): Promise<boolean> {\n console.warn('The default RxapAuthenticationService implementation should only be used in a development environment!');\n return Promise.resolve(false);\n }\n\n public isAuthenticated(): Promise<boolean> {\n return TimeoutPromise((resolve) => {\n resolve(localStorage.getItem(RXAP_AUTHENTICATION_LOCAL_STORAGE_KEY) === 'true');\n }, 2500);\n }\n\n}\n","import { InjectionToken } from '@angular/core';\n\nexport const RXAP_AUTHENTICATION_DEACTIVATED = new InjectionToken<boolean>('rxap/authentication/deactivated');\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport {\n CanActivate,\n CanActivateChild,\n ActivatedRouteSnapshot,\n RouterStateSnapshot,\n UrlTree,\n Router\n} from '@angular/router';\nimport { Observable } from 'rxjs';\nimport { RxapAuthenticationService } from './authentication.service';\nimport {\n map,\n first,\n take\n} from 'rxjs/operators';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\n\n@Injectable({ providedIn: 'root' })\nexport class RxapAuthenticationGuard implements CanActivate, CanActivateChild {\n\n public lastUrl: string | null = null;\n\n constructor(\n @Inject(RxapAuthenticationService)\n public authentication: RxapAuthenticationService,\n @Inject(Router)\n public router: Router,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {}\n\n public canActivate(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate', state.url);\n return this.checkAuthStatus(route, state);\n }\n\n public canActivateChild(\n childRoute: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n console.debug('[RxapAuthenticationGuard] can activate child', state.url);\n return this.checkAuthStatus(childRoute, state);\n }\n\n private async checkAuthStatus(\n route: ActivatedRouteSnapshot,\n state: RouterStateSnapshot\n ): Promise<UrlTree | boolean> {\n\n if (this.deactivated) {\n return true;\n }\n\n const authenticated = await this.authentication.isAuthenticated();\n\n if (authenticated === null) {\n if (!this.lastUrl || (state.url !== '/' && !state.url.match(/authentication\\/login/))) {\n this.lastUrl = state.url;\n }\n return this.router.createUrlTree([ '/', 'authentication', 'loading' ]);\n }\n if (authenticated) {\n if (this.lastUrl && (state.url/*?*/ === '/' || state.url.match(/authentication\\/login/))) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n } else {\n if (state.url.match(/authentication/)) {\n if (state.url.match(/authentication\\/reset-password/)) {\n return true;\n }\n return this.router.createUrlTree([ '/' ]);\n } else {\n this.lastUrl = null;\n return true;\n }\n }\n } else {\n if (!state.url.match(/^\\/?authentication/)) {\n this.lastUrl = state.url;\n }\n if (state.url.match(/^\\/?authentication/)) {\n if (this.lastUrl && this.lastUrl.match(/^\\/?authentication/)) {\n const lastUrl = this.lastUrl;\n this.lastUrl = null;\n return this.createUrlTreeToLastUrl(lastUrl);\n }\n return true;\n } else {\n return this.router.createUrlTree([ '/', 'authentication', 'login' ]);\n }\n }\n\n }\n\n private createUrlTreeToLastUrl(lastUrl: string): UrlTree {\n\n const urlMatch = lastUrl.match(/^([^?#]+)(\\?([^#]+))?(#(.+))?$/);\n\n if (urlMatch) {\n\n let queryParams: Record<string, string> = {};\n\n if (urlMatch[3]) {\n const queryParamsString = urlMatch[ 3 ];\n queryParams = queryParamsString.split('&').map(param => {\n const split = param.split('=');\n return { [ split[ 0 ] ]: split[ 1 ] };\n }).reduce((params, param) => ({ ...params, ...param }), {});\n }\n\n let fragment: string | undefined = undefined;\n\n if (urlMatch[5]) {\n fragment = urlMatch[5];\n }\n\n return this.router.createUrlTree([urlMatch[1]], {\n queryParams,\n fragment,\n });\n\n }\n\n return this.router.createUrlTree([lastUrl]);\n\n }\n\n}\n","import { Injectable } from '@angular/core';\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class RegisterService {\n\n constructor() {\n console.warn('The default RegisterService implementation should only be used in a development environment!');\n }\n\n public register(email: string, password: string): Promise<boolean> {\n return Promise.resolve(true);\n }\n\n}\n","import { Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\n\nexport interface UserProfile {\n username: string;\n firstname?: string;\n lastname?: string;\n name?: string;\n email: string;\n photoURL?: string;\n avatarUrl?: string;\n}\n\n@Injectable({ providedIn: 'root' })\n/* ignore coverage */\nexport class UserService<User extends UserProfile = UserProfile> {\n\n public user$ = new BehaviorSubject<User | null>(null);\n\n}\n","import {\n Injectable,\n Inject,\n Optional\n} from '@angular/core';\nimport { Router } from '@angular/router';\nimport { RxapAuthenticationService } from './authentication.service';\nimport { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';\nimport { tap } from 'rxjs/operators';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AuthenticationRoutingService {\n\n constructor(\n @Inject(Router)\n private readonly router: Router,\n @Inject(RxapAuthenticationService)\n private readonly authenticationService: RxapAuthenticationService,\n @Optional()\n @Inject(RXAP_AUTHENTICATION_DEACTIVATED)\n private readonly deactivated: boolean | null = null\n ) {\n if (!deactivated) {\n console.log('Authentication is enabled');\n this.authenticationService.isAuthenticated$.pipe(\n tap(isAuthenticated => {\n if (isAuthenticated) {\n return this.router.navigate([ '/' ]);\n } else {\n return this.router.navigate([ '/', 'authentication', 'login' ]);\n }\n })\n ).subscribe();\n }\n }\n\n}\n","import {\n Directive,\n NgModule,\n HostListener,\n EventEmitter,\n Output\n} from '@angular/core';\nimport { RxapAuthenticationService } from './authentication.service';\n\n@Directive({\n selector: '[rxapSignOut]'\n})\nexport class SignOutDirective {\n\n @Output()\n public successful = new EventEmitter<void>();\n\n @Output()\n public failure = new EventEmitter<Error>();\n\n constructor(private readonly auth: RxapAuthenticationService) { }\n\n @HostListener('click')\n public async onClick() {\n try {\n await this.auth.signOut();\n this.successful.emit();\n } catch (e: any) {\n this.failure.emit(e);\n }\n }\n\n}\n\n@NgModule({\n declarations: [ SignOutDirective ],\n exports: [ SignOutDirective ]\n})\nexport class SignOutDirectiveModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;MAaa,qCAAqC,GAAG,sBAAsB;SAe3D,cAAc,CAAI,QAA6E,EAAE,EAAU;IACzH,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM;QAEpC,UAAU,CAAC;YACT,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;SAC3B,EAAE,EAAE,CAAC,CAAC;KAER,CAAC,CAAC;AACL,CAAC;SAEe,cAAc,CAAI,KAAQ,EAAE,EAAU;IACpD,OAAO,IAAI,OAAO,CAAC,OAAO;QAExB,UAAU,CAAC;YACT,OAAO,CAAC,KAAK,CAAC,CAAC;SAChB,EAAE,EAAE,CAAC,CAAC;KAER,CAAC,CAAC;AACL,CAAC;AAGD;MACa,yBAAyB;IAIpC;QAFO,qBAAgB,GAAG,IAAI,eAAe,CAAiB,IAAI,CAAC,CAAC;QAGlE,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,IAAI,CAAC,eAAe,EAAE,CAAC,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;KAC7F;IAEM,oBAAoB,CAAC,KAAa;QACvC,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,OAAO,cAAc,CAAC,KAAK,KAAK,WAAW,EAAE,IAAI,CAAC,CAAC;KACpD;IAEM,iBAAiB,CAAC,QAAgB,EAAE,KAAa;QACtD,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAAC,CAAC;QACvH,OAAO,cAAc,CAAC,QAAQ,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC;KAClD;IAEM,MAAM,0BAA0B,CAAC,KAAa,EAAE,QAAgB,EAAE,QAAiB;QACxF,OAAO,CAAC,IAAI,CAAC,wGAAwG,CAA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AAC,yBAAyB;;0BAEhC,QAAQ;;0BACR,MAAM;2BAAC,+BAA+B;;;MCT9B,gBAAgB;IAQ3B,YAA6B,IAA+B;QAA/B,SAAI,GAAJ,IAAI,CAA2B;QALrD,eAAU,GAAG,IAAI,YAAY,EAAQ,CAAC;QAGtC,YAAO,GAAG,IAAI,YAAY,EAAS,CAAC;KAEsB;IAG1D,MAAM,OAAO;QAClB,IAAI;YACF,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;SACxB;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACtB;KACF;;6GAlBU,gBAAgB;iGAAhB,gBAAgB;2FAAhB,gBAAgB;kBAH5B,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;iBAC1B;6GAIQ,UAAU;sBADhB,MAAM;gBAIA,OAAO;sBADb,MAAM;gBAMM,OAAO;sBADnB,YAAY;uBAAC,OAAO;;MAgBV,sBAAsB;;mHAAtB,sBAAsB;oHAAtB,sBAAsB,iBA1BtB,gBAAgB,aAAhB,gBAAgB;oHA0BhB,sBAAsB;2FAAtB,sBAAsB;kBAJlC,QAAQ;mBAAC;oBACR,YAAY,EAAE,CAAE,gBAAgB,CAAE;oBAClC,OAAO,EAAO,CAAE,gBAAgB,CAAE;iBACnC;;;ACrCD;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxap/authentication",
|
|
3
|
-
"version": "13.0.0-next.
|
|
3
|
+
"version": "13.0.0-next.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Merzough Münker",
|
|
6
6
|
"homepage": "https://gitlab.com/rxap/packages/libs/authentication",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"@angular/router": "^13.2.3",
|
|
44
44
|
"@rxap/config": "^13.0.0-next.0",
|
|
45
45
|
"@rxap/definition": "^13.0.0-next.0",
|
|
46
|
-
"@rxap/directives": "^13.0.0-next.
|
|
47
|
-
"@rxap/forms": "^13.0.0-next.
|
|
46
|
+
"@rxap/directives": "^13.0.0-next.1",
|
|
47
|
+
"@rxap/forms": "^13.0.0-next.1",
|
|
48
48
|
"@rxap/services": "^13.0.0-next.0",
|
|
49
|
-
"@rxap/utilities": "^13.0.0-next.
|
|
49
|
+
"@rxap/utilities": "^13.0.0-next.1",
|
|
50
50
|
"reflect-metadata": "^0.1.13",
|
|
51
51
|
"rxjs": "^6.5.5"
|
|
52
52
|
},
|