guard and routing issue fixed

This commit is contained in:
bitbucket 2023-03-14 15:36:41 +05:30
parent ed6ec8a57b
commit dcd14c9f7a
16 changed files with 137 additions and 89 deletions

View File

@ -33,7 +33,8 @@
"crossvent", "crossvent",
"calendar-utils/date-adapters/date-fns", "calendar-utils/date-adapters/date-fns",
"contra/emitter", "contra/emitter",
"@mattlewis92/dom-autoscroller" "@mattlewis92/dom-autoscroller",
"CommonJS"
], ],
"styles": [ "styles": [
"node_modules/quill/dist/quill.snow.css", "node_modules/quill/dist/quill.snow.css",

View 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']);
// }
// }
}

View File

@ -38,6 +38,7 @@ import { TokenInterceptor } from './_guard/token.interceptor';
import { SessionService } from './session-services/session.service'; import { SessionService } from './session-services/session.service';
import { AppointmentService } from './appoinment/appointment.service'; import { AppointmentService } from './appoinment/appointment.service';
import { RoleMenuItemsPipe } from './layouts/role-menu-items.pipe'; import { RoleMenuItemsPipe } from './layouts/role-menu-items.pipe';
import { AuthGuard } from './_guard/auth.guard';
export function HttpLoaderFactory(http: HttpClient) { export function HttpLoaderFactory(http: HttpClient) {
@ -91,7 +92,7 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {
], ],
providers: [ providers: [
TranslateService, TranslateService,
SessionService, SessionService,AuthGuard,
AppointmentService, AppointmentService,
{ {
provide: PERFECT_SCROLLBAR_CONFIG, provide: PERFECT_SCROLLBAR_CONFIG,

View File

@ -2,6 +2,7 @@ import { Routes } from '@angular/router';
import { AdminLayoutComponent } from './layouts/admin/admin-layout.component'; import { AdminLayoutComponent } from './layouts/admin/admin-layout.component';
import { AuthLayoutComponent } from './layouts/auth/auth-layout.component'; import { AuthLayoutComponent } from './layouts/auth/auth-layout.component';
import { AuthGuard } from './_guard/auth.guard';
export const AppRoutes: Routes = [{ export const AppRoutes: Routes = [{
path: '', path: '',
@ -10,34 +11,41 @@ export const AppRoutes: Routes = [{
}, { }, {
path: '', path: '',
component: AdminLayoutComponent, component: AdminLayoutComponent,
canActivateChild:[AuthGuard],
children: [{ children: [{
path: 'home', path: 'home',
loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule) loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)
}, },
{
path: 'business',
loadChildren: () => import('./appoinment/business/business.module').then(m => m.BusinessModule)
},
{ {
path: 'appoinments', path: 'appoinments',
loadChildren: () => import('./appoinment/appoinments/appoinments.module').then(m => m.AppoinmentsModule) loadChildren: () => import('./appoinment/appoinments/appoinments.module').then(m => m.AppoinmentsModule)
}, },
{ {
path: 'service', path: 'appoinment',
loadChildren: () => import('./appoinment/service-list-details/service-list.module').then(m => m.ServiceListModule) loadChildren: () => import('./appoinment/appoinment.module').then(m => m.AppoinmentModule)
},
{
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: 'customers', path: 'customers',
loadChildren: () => import('./appoinment/customers/customers.module').then(m => m.CustomersModule) loadChildren: () => import('./appoinment/customers/customers.module').then(m => m.CustomersModule)
}, },
{ {
path: 'business', path: 'consultants',
loadChildren: () => import('./appoinment/business/business.module').then(m => m.BusinessModule) 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: '', path: '',

View File

@ -12,23 +12,15 @@ import { } from './service-list-details/service-list/service-list.component'
import { ConsultantsListComponent } from './consultants/consultants-list/consultants-list.component'; import { ConsultantsListComponent } from './consultants/consultants-list/consultants-list.component';
const routes: Routes = [ const routes: Routes = [ {
// { path: 'add-business-list',
// path:'', component: AddBusinessListComponent
// redirectTo:'', },
// pathMatch:'full'
// },{ {
// path: 'add-business-list', path: 'add-user-list',
// component: AddBusinessListComponent component: AddUserListComponent
// }, },
// {
// path: 'business-list',
// component: BusinessListComponent
// },
// {
// path: 'add-user-list',
// component: AddUserListComponent
// },
// { // {
// path: 'user-list', // path: 'user-list',
// component: UserListComponent // component: UserListComponent
@ -41,10 +33,10 @@ const routes: Routes = [
// path: 'customers-list', // path: 'customers-list',
// component: CustomersListComponent // component: CustomersListComponent
// }, // },
// // { // {
// // path: 'calendar-list', // path: 'calendar-list',
// // component: CalendarListComponent // component: CalendarListComponent
// // }, // },
// { // {
// path: 'calendar-list', // path: 'calendar-list',
// component: CalendarListComponent // component: CalendarListComponent

View File

@ -19,7 +19,7 @@ import { ConsultantsModule } from './consultants/consultants.module';
DemoMaterialModule, DemoMaterialModule,
CommonModule, CommonModule,
AppoinmentRoutingModule, AppoinmentRoutingModule,
BusinessModule,
UserModule, UserModule,
AppoinmentsModule, AppoinmentsModule,
CustomersModule, CustomersModule,

View File

@ -4,14 +4,11 @@ import { AppoinmentsListComponent } from './appoinments-list/appoinments-list.co
const routes: Routes = [ const routes: Routes = [
{ {
path:'',
redirectTo:'appoinment/appoinments', path: '',
pathMatch:'full' component: AppoinmentsListComponent
},
{ }
path:'appoinment/appoinments',
component:AppoinmentsListComponent
},
]; ];
@NgModule({ @NgModule({

View File

@ -4,14 +4,9 @@ import { BusinessListComponent } from './business-list/business-list.component';
const routes: Routes = [ const routes: Routes = [
{ {
path:'', path: '',
redirectTo:'appoinment/business', component: BusinessListComponent
pathMatch:'full' }
},
{
path:'appoinment/business',
component:BusinessListComponent
},
]; ];
@NgModule({ @NgModule({

View File

@ -4,14 +4,9 @@ import { ConsultantsListComponent } from './consultants-list/consultants-list.co
const routes: Routes = [ const routes: Routes = [
{ {
path:'', path: '',
redirectTo:'appoinment/consultants', component: ConsultantsListComponent
pathMatch:'full' }
},
{
path:'appoinment/consultants',
component:ConsultantsListComponent
},
]; ];
@NgModule({ @NgModule({

View File

@ -4,13 +4,8 @@ import { CustomersListComponent } from './customers-list/customers-list.componen
const routes: Routes = [ const routes: Routes = [
{ {
path:'', path: '',
redirectTo:'appoinment/customers', component: CustomersListComponent
pathMatch:'full'
},
{
path:'appoinment/customers',
component:CustomersListComponent
}, },
]; ];

View File

@ -2,15 +2,10 @@ import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { ServiceListComponent } from './service-list/service-list.component'; import { ServiceListComponent } from './service-list/service-list.component';
const routes: Routes = [ const routes: Routes = [
{ {
path:'', path: '',
redirectTo:'appoinment/service', component: ServiceListComponent
pathMatch:'full'
},
{
path:'appoinment/service',
component:ServiceListComponent
}, },
]; ];

View File

@ -5,13 +5,8 @@ import { UserModule } from './user.module';
const routes: Routes = [ const routes: Routes = [
{ {
path:'', path: '',
redirectTo:'appoinment/users', component: UserListComponent
pathMatch:'full'
},
{
path:'appoinment/users',
component:UserListComponent
}, },
]; ];

View File

@ -0,0 +1 @@
<h1>welcome</h1>

View File

@ -29,7 +29,7 @@ const HORIZONTALMENUITEMS = [
icon: 'explore' icon: 'explore'
}, },
{ {
state: 'appoinments', state: 'appoinment',
name: 'Appoinments', name: 'Appoinments',
type: 'link', type: 'link',
icon: 'security', icon: 'security',
@ -38,7 +38,7 @@ const HORIZONTALMENUITEMS = [
// ] // ]
}, },
{ {
state: 'business', state: 'appoinment',
name: 'Business', name: 'Business',
type: 'link', type: 'link',
icon: 'security', icon: 'security',
@ -57,7 +57,7 @@ const HORIZONTALMENUITEMS = [
// ] // ]
// }, // },
{ {
state: 'customers', state: 'appoinment',
name: 'Customers', name: 'Customers',
type: 'link', type: 'link',
icon: 'security', icon: 'security',
@ -66,7 +66,7 @@ const HORIZONTALMENUITEMS = [
// ] // ]
}, },
{ {
state: 'consultants', state: 'appoinment',
name: 'Consultants', name: 'Consultants',
type: 'link', type: 'link',
icon: 'security', icon: 'security',
@ -75,7 +75,7 @@ const HORIZONTALMENUITEMS = [
// ] // ]
}, },
{ {
state: 'users', state: 'appoinment',
name: 'Users', name: 'Users',
type: 'link', type: 'link',
icon: 'security', icon: 'security',
@ -85,7 +85,7 @@ const HORIZONTALMENUITEMS = [
// ] // ]
}, },
{ {
state: 'service', state: 'appoinment',
name: 'Services List', name: 'Services List',
type: 'link', type: 'link',
icon: 'security', icon: 'security',

View File

@ -84,7 +84,7 @@ const MENUITEMS : Menu[] = [
// ] // ]
}, },
{ {
state: 'service', state: 'services',
name: 'Services List', name: 'Services List',
type: 'link', type: 'link',
icon: 'security', icon: 'security',

3
package-lock.json generated Normal file
View File

@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}