Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
"src/assets"
],
"styles": [
"src/scss/styles.scss"
"src/scss/styles.scss",
"node_modules/primeng/resources/themes/lara-light-blue/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"node_modules/primeicons/primeicons.css"
],
"scripts": [],
"allowedCommonJsDependencies": [],
Expand Down
163 changes: 152 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,24 @@
"@angular/platform-browser": "^21.0.6",
"@angular/platform-browser-dynamic": "^21.0.6",
"@angular/router": "^21.0.6",
"@auth0/angular-jwt": "^5.2.0",
"@coreui/angular": "~5.6.4",
"@coreui/angular-chartjs": "~5.6.4",
"@coreui/chartjs": "~4.1.0",
"@coreui/coreui": "~5.5.0",
"@coreui/icons": "^3.0.1",
"@coreui/icons-angular": "~5.6.4",
"@coreui/utils": "^2.0.2",
"@types/mime-types": "^3.0.1",
"chart.js": "^4.5.1",
"jwt-decode": "^4.0.0",
"lodash-es": "^4.17.22",
"mime": "^4.1.0",
"mime-types": "^3.0.2",
"ngx-scrollbar": "^13.0.3",
"primeicons": "^7.0.0",
"primeng": "^21.0.2",
"react-spinners": "^0.17.0",
"rxjs": "~7.8.2",
"tslib": "^2.8.1",
"zone.js": "~0.16.0"
Expand Down
18 changes: 18 additions & 0 deletions src/app/Interceptor/auth.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HttpInterceptorFn, HttpRequest, HttpEvent, HttpHandlerFn } from '@angular/common/http';
import { Observable } from 'rxjs';

export const authInterceptor: HttpInterceptorFn = (req: HttpRequest<unknown>, next: HttpHandlerFn): Observable<HttpEvent<unknown>> => {
// Get token logic...
const token = localStorage.getItem('token'); // Replace with actual token retrieval

if (token) {
const authReq = req.clone({
setHeaders: {
Authorization: `Bearer ${token}`
}
});
return next(authReq);
}

return next(req);
};
28 changes: 28 additions & 0 deletions src/app/RouteGuard/AuthGuard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from '../services/auth.service'; // Assume you have an authentication service

@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
decodeToken:any;
decodedTxt:any;
constructor(private authService: AuthService, private router: Router) {}

canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
this.decodeToken = this.authService.getDecodeToken();
this.decodedTxt = JSON.parse(this.decodeToken);
if (this.decodedTxt?.isAdmin) {
console.log("Admin")
this.router.navigate(['/forms/form-control']);
return true
} else {
console.log("User")
return false; // Block navigation
}
}
}
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { iconSubset } from './icons/icon-subset';
imports: [RouterOutlet]
})
export class AppComponent implements OnInit {
title = 'CoreUI Angular Admin Template';
title = 'Ecomm';

readonly #destroyRef: DestroyRef = inject(DestroyRef);
readonly #activatedRoute: ActivatedRoute = inject(ActivatedRoute);
Expand Down
6 changes: 5 additions & 1 deletion src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import {
} from '@angular/router';
import { IconSetService } from '@coreui/icons-angular';
import { routes } from './app.routes';
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import {authInterceptor} from './Interceptor/auth.interceptor';
import { provideAnimations } from '@angular/platform-browser/animations';

export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(withInterceptors([authInterceptor])),
provideRouter(routes,
withRouterConfig({
onSameUrlNavigation: 'reload'
Expand All @@ -26,7 +30,7 @@ export const appConfig: ApplicationConfig = {
withHashLocation()
),
IconSetService,
provideAnimationsAsync()
provideAnimations()
]
};

Loading