1- import { Injectable } from '@angular/core' ;
1+ import { Injectable , inject } from '@angular/core' ;
22import { UserService } from './user.service' ;
33import { Observable , of } from 'rxjs' ;
44import { switchMap , map } from 'rxjs/operators' ;
5- import { Router , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ;
5+ import { Router , ActivatedRouteSnapshot , RouterStateSnapshot , CanActivateFn } from '@angular/router' ;
66import { PouchAuthService } from './database/pouch-auth.service' ;
77import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog' ;
88import { LoginDialogComponent } from '../login/login-dialog.component' ;
9+ import { StateService } from './state.service' ;
910
1011@Injectable ( {
1112 providedIn : 'root'
@@ -16,7 +17,8 @@ export class AuthService {
1617 private userService : UserService ,
1718 private router : Router ,
1819 private pouchAuthService : PouchAuthService ,
19- private dialog : MatDialog
20+ private dialog : MatDialog ,
21+ private stateService : StateService
2022 ) { }
2123
2224 private getSession$ ( ) {
@@ -42,10 +44,10 @@ export class AuthService {
4244 return dialogRef . afterClosed ( ) . pipe ( switchMap ( loginState => {
4345 if ( loginState === undefined ) {
4446 // If the current routerState snapshot url is a blank string, the user got here via
45- // directly pasting in a link to a guarded route. Need to reroute to the community page
47+ // directly pasting in a link to a guarded route. Need to reroute to the appropriate default page
4648 // before closing the dialog.
4749 if ( this . router . routerState . snapshot . url === '' ) {
48- this . router . navigate ( [ '/' ] ) ;
50+ this . router . navigate ( [ this . stateService . configuration . planetType === 'center' ? '/login' : '/' ] ) ;
4951 }
5052 return of ( false ) ;
5153 }
@@ -74,7 +76,7 @@ export class AuthService {
7476 return this . getSession$ ( ) . pipe (
7577 map ( ( sessionInfo ) => {
7678 if ( sessionInfo . userCtx . name ) {
77- this . router . navigate ( [ '' ] ) ;
79+ this . router . navigate ( [ this . stateService . configuration . planetType === 'center' ? '/myDashboard' : '' ] ) ;
7880 return false ;
7981 }
8082 return true ;
@@ -93,4 +95,16 @@ export class AuthService {
9395 ) ;
9496 }
9597
98+ static centerLandingGuard : CanActivateFn = ( ) => {
99+ const router = inject ( Router ) ;
100+ const stateService = inject ( StateService ) ;
101+
102+ // Only redirect on first navigation for center planets
103+ if ( ! router . navigated && stateService . configuration . planetType === 'center' ) {
104+ router . navigate ( [ '/login' ] ) ;
105+ return false ;
106+ }
107+ return true ;
108+ } ;
109+
96110}
0 commit comments