guard and routing issue fixed
This commit is contained in:
parent
ed6ec8a57b
commit
dcd14c9f7a
@ -33,7 +33,8 @@
|
||||
"crossvent",
|
||||
"calendar-utils/date-adapters/date-fns",
|
||||
"contra/emitter",
|
||||
"@mattlewis92/dom-autoscroller"
|
||||
"@mattlewis92/dom-autoscroller",
|
||||
"CommonJS"
|
||||
],
|
||||
"styles": [
|
||||
"node_modules/quill/dist/quill.snow.css",
|
||||
|
||||
70
ng-seed/src/app/_guard/auth.guard.ts
Normal file
70
ng-seed/src/app/_guard/auth.guard.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild } from '@angular/router';
|
||||
import { Observable , of } from 'rxjs';
|
||||
// import { CognitoService } from '../AwsService/cognito.service';
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
|
||||
constructor(private router: Router) { }
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
|
||||
const token = localStorage.getItem('user_token');
|
||||
|
||||
if(token != '' && token != undefined && token != null){
|
||||
return true
|
||||
}else{
|
||||
alert("else");
|
||||
this.router.navigate(['authentication/login']);
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (this.shared.getToken()) {
|
||||
// alert("if");
|
||||
// // this.router.navigate(['']);
|
||||
// return true
|
||||
// } else {
|
||||
// alert("else");
|
||||
// this.router.navigate(['/login']);
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
|
||||
|
||||
const token = localStorage.getItem('user_token');
|
||||
console.log(token)
|
||||
if(token != '' && token != undefined && token != null){
|
||||
return true
|
||||
}else{
|
||||
setTimeout(() => {
|
||||
this.router.navigate(['authentication/login']);
|
||||
return false;
|
||||
},1000);
|
||||
}
|
||||
|
||||
// if (this.shared.getCurrentUser() != null && this.shared.getToken()) {
|
||||
// // alert("if");
|
||||
|
||||
// return true;
|
||||
// } else {
|
||||
// // alert("else");
|
||||
// setTimeout(() => {
|
||||
// this.router.navigate(['authentication/login']);
|
||||
// return false;
|
||||
// },1000);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
// public getToken(): string {
|
||||
// return localStorage.getItem('token');
|
||||
// }
|
||||
|
||||
// public logOut() {
|
||||
// localStorage.clear();
|
||||
// if(localStorage.getItem('token') === null){
|
||||
// this.router.navigate(['/login']);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@ -38,6 +38,7 @@ import { TokenInterceptor } from './_guard/token.interceptor';
|
||||
import { SessionService } from './session-services/session.service';
|
||||
import { AppointmentService } from './appoinment/appointment.service';
|
||||
import { RoleMenuItemsPipe } from './layouts/role-menu-items.pipe';
|
||||
import { AuthGuard } from './_guard/auth.guard';
|
||||
|
||||
|
||||
export function HttpLoaderFactory(http: HttpClient) {
|
||||
@ -91,7 +92,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
|
||||
],
|
||||
providers: [
|
||||
TranslateService,
|
||||
SessionService,
|
||||
SessionService,AuthGuard,
|
||||
AppointmentService,
|
||||
{
|
||||
provide: PERFECT_SCROLLBAR_CONFIG,
|
||||
|
||||
@ -2,6 +2,7 @@ import { Routes } from '@angular/router';
|
||||
|
||||
import { AdminLayoutComponent } from './layouts/admin/admin-layout.component';
|
||||
import { AuthLayoutComponent } from './layouts/auth/auth-layout.component';
|
||||
import { AuthGuard } from './_guard/auth.guard';
|
||||
|
||||
export const AppRoutes: Routes = [{
|
||||
path: '',
|
||||
@ -10,34 +11,41 @@ export const AppRoutes: Routes = [{
|
||||
}, {
|
||||
path: '',
|
||||
component: AdminLayoutComponent,
|
||||
canActivateChild:[AuthGuard],
|
||||
children: [{
|
||||
path: 'home',
|
||||
loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
|
||||
},
|
||||
{
|
||||
path: 'business',
|
||||
loadChildren: () => import('./appoinment/business/business.module').then(m => m.BusinessModule)
|
||||
},
|
||||
{
|
||||
path: 'appoinments',
|
||||
loadChildren: () => import('./appoinment/appoinments/appoinments.module').then(m => m.AppoinmentsModule)
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
path: 'service',
|
||||
loadChildren: () => import('./appoinment/service-list-details/service-list.module').then(m => m.ServiceListModule)
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
loadChildren: () => import('./appoinment/user/user.module').then(m => m.UserModule)
|
||||
},
|
||||
{
|
||||
path: 'consultants',
|
||||
loadChildren: () => import('./appoinment/consultants/consultants.module').then(m => m.ConsultantsModule)
|
||||
path: 'appoinment',
|
||||
loadChildren: () => import('./appoinment/appoinment.module').then(m => m.AppoinmentModule)
|
||||
},
|
||||
{
|
||||
path: 'customers',
|
||||
loadChildren: () => import('./appoinment/customers/customers.module').then(m => m.CustomersModule)
|
||||
},
|
||||
{
|
||||
path: 'business',
|
||||
loadChildren: () => import('./appoinment/business/business.module').then(m => m.BusinessModule)
|
||||
path: 'consultants',
|
||||
loadChildren: () => import('./appoinment/consultants/consultants.module').then(m => m.ConsultantsModule)
|
||||
}, {
|
||||
path: 'users',
|
||||
loadChildren: () => import('./appoinment/user/user.module').then(m => m.UserModule)
|
||||
},
|
||||
{
|
||||
path: 'services',
|
||||
loadChildren: () => import('./appoinment/service-list-details/service-list.module').then(m => m.ServiceListModule)
|
||||
}
|
||||
|
||||
]
|
||||
}, {
|
||||
path: '',
|
||||
|
||||
@ -12,23 +12,15 @@ import { } from './service-list-details/service-list/service-list.component'
|
||||
import { ConsultantsListComponent } from './consultants/consultants-list/consultants-list.component';
|
||||
|
||||
|
||||
const routes: Routes = [
|
||||
// {
|
||||
// path:'',
|
||||
// redirectTo:'',
|
||||
// pathMatch:'full'
|
||||
// },{
|
||||
// path: 'add-business-list',
|
||||
// component: AddBusinessListComponent
|
||||
// },
|
||||
// {
|
||||
// path: 'business-list',
|
||||
// component: BusinessListComponent
|
||||
// },
|
||||
// {
|
||||
// path: 'add-user-list',
|
||||
// component: AddUserListComponent
|
||||
// },
|
||||
const routes: Routes = [ {
|
||||
path: 'add-business-list',
|
||||
component: AddBusinessListComponent
|
||||
},
|
||||
|
||||
{
|
||||
path: 'add-user-list',
|
||||
component: AddUserListComponent
|
||||
},
|
||||
// {
|
||||
// path: 'user-list',
|
||||
// component: UserListComponent
|
||||
@ -41,10 +33,10 @@ const routes: Routes = [
|
||||
// path: 'customers-list',
|
||||
// component: CustomersListComponent
|
||||
// },
|
||||
// // {
|
||||
// // path: 'calendar-list',
|
||||
// // component: CalendarListComponent
|
||||
// // },
|
||||
// {
|
||||
// path: 'calendar-list',
|
||||
// component: CalendarListComponent
|
||||
// },
|
||||
// {
|
||||
// path: 'calendar-list',
|
||||
// component: CalendarListComponent
|
||||
|
||||
@ -19,7 +19,7 @@ import { ConsultantsModule } from './consultants/consultants.module';
|
||||
DemoMaterialModule,
|
||||
CommonModule,
|
||||
AppoinmentRoutingModule,
|
||||
BusinessModule,
|
||||
|
||||
UserModule,
|
||||
AppoinmentsModule,
|
||||
CustomersModule,
|
||||
|
||||
@ -4,14 +4,11 @@ import { AppoinmentsListComponent } from './appoinments-list/appoinments-list.co
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path:'',
|
||||
redirectTo:'appoinment/appoinments',
|
||||
pathMatch:'full'
|
||||
},
|
||||
{
|
||||
path:'appoinment/appoinments',
|
||||
component:AppoinmentsListComponent
|
||||
},
|
||||
|
||||
path: '',
|
||||
component: AppoinmentsListComponent
|
||||
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
||||
@ -4,14 +4,9 @@ import { BusinessListComponent } from './business-list/business-list.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path:'',
|
||||
redirectTo:'appoinment/business',
|
||||
pathMatch:'full'
|
||||
},
|
||||
{
|
||||
path:'appoinment/business',
|
||||
component:BusinessListComponent
|
||||
},
|
||||
path: '',
|
||||
component: BusinessListComponent
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
||||
@ -4,14 +4,9 @@ import { ConsultantsListComponent } from './consultants-list/consultants-list.co
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path:'',
|
||||
redirectTo:'appoinment/consultants',
|
||||
pathMatch:'full'
|
||||
},
|
||||
{
|
||||
path:'appoinment/consultants',
|
||||
component:ConsultantsListComponent
|
||||
},
|
||||
path: '',
|
||||
component: ConsultantsListComponent
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
||||
@ -4,13 +4,8 @@ import { CustomersListComponent } from './customers-list/customers-list.componen
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path:'',
|
||||
redirectTo:'appoinment/customers',
|
||||
pathMatch:'full'
|
||||
},
|
||||
{
|
||||
path:'appoinment/customers',
|
||||
component:CustomersListComponent
|
||||
path: '',
|
||||
component: CustomersListComponent
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -2,15 +2,10 @@ import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { ServiceListComponent } from './service-list/service-list.component';
|
||||
|
||||
const routes: Routes = [
|
||||
const routes: Routes = [
|
||||
{
|
||||
path:'',
|
||||
redirectTo:'appoinment/service',
|
||||
pathMatch:'full'
|
||||
},
|
||||
{
|
||||
path:'appoinment/service',
|
||||
component:ServiceListComponent
|
||||
path: '',
|
||||
component: ServiceListComponent
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -5,13 +5,8 @@ import { UserModule } from './user.module';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path:'',
|
||||
redirectTo:'appoinment/users',
|
||||
pathMatch:'full'
|
||||
},
|
||||
{
|
||||
path:'appoinment/users',
|
||||
component:UserListComponent
|
||||
path: '',
|
||||
component: UserListComponent
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
<h1>welcome</h1>
|
||||
@ -29,7 +29,7 @@ const HORIZONTALMENUITEMS = [
|
||||
icon: 'explore'
|
||||
},
|
||||
{
|
||||
state: 'appoinments',
|
||||
state: 'appoinment',
|
||||
name: 'Appoinments',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
@ -38,7 +38,7 @@ const HORIZONTALMENUITEMS = [
|
||||
// ]
|
||||
},
|
||||
{
|
||||
state: 'business',
|
||||
state: 'appoinment',
|
||||
name: 'Business',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
@ -57,7 +57,7 @@ const HORIZONTALMENUITEMS = [
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
state: 'customers',
|
||||
state: 'appoinment',
|
||||
name: 'Customers',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
@ -66,7 +66,7 @@ const HORIZONTALMENUITEMS = [
|
||||
// ]
|
||||
},
|
||||
{
|
||||
state: 'consultants',
|
||||
state: 'appoinment',
|
||||
name: 'Consultants',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
@ -75,7 +75,7 @@ const HORIZONTALMENUITEMS = [
|
||||
// ]
|
||||
},
|
||||
{
|
||||
state: 'users',
|
||||
state: 'appoinment',
|
||||
name: 'Users',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
@ -85,7 +85,7 @@ const HORIZONTALMENUITEMS = [
|
||||
// ]
|
||||
},
|
||||
{
|
||||
state: 'service',
|
||||
state: 'appoinment',
|
||||
name: 'Services List',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
|
||||
@ -84,7 +84,7 @@ const MENUITEMS : Menu[] = [
|
||||
// ]
|
||||
},
|
||||
{
|
||||
state: 'service',
|
||||
state: 'services',
|
||||
name: 'Services List',
|
||||
type: 'link',
|
||||
icon: 'security',
|
||||
|
||||
3
package-lock.json
generated
Normal file
3
package-lock.json
generated
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user