### File

`src/lib/authentication-routing.service.ts`

### Constructor

`constructor(router: Router, authenticationService: RxapAuthenticationService, deactivated: boolean | null)`
Defined in src/lib/authentication-routing.service.ts:14
Parameters :
Name | Type | Optional
router | `Router` | No
authenticationService | `RxapAuthenticationService` | No
deactivated | `boolean | null` | No

    import {
      Inject,
      Injectable,
      Optional,
    } from '@angular/core';
    import { Router } from '@angular/router';
    import { RxapAuthenticationService } from './authentication.service';
    import { RXAP_AUTHENTICATION_DEACTIVATED } from './tokens';
    import { tap } from 'rxjs/operators';

    @Injectable({
      providedIn: 'root',
    })
    export class AuthenticationRoutingService {

      constructor(
        @Inject(Router)
        private readonly router: Router,
        @Inject(RxapAuthenticationService)
        private readonly authenticationService: RxapAuthenticationService,
        @Optional()
        @Inject(RXAP_AUTHENTICATION_DEACTIVATED)
        private readonly deactivated: boolean | null = null,
      ) {
        if (!deactivated) {
          console.log('Authentication is enabled');
          this.authenticationService.isAuthenticated$.pipe(
            tap(isAuthenticated => {
              if (isAuthenticated) {
                return this.router.navigate([ '/' ]);
              } else {
                return this.router.navigate([ '/', 'authentication', 'login' ]);
              }
            }),
          ).subscribe();
        }
      }

    }

# results matching ""

# No results matching ""