diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 6d1e015..b609473 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -7,7 +7,7 @@ import {DialogModule} from 'primeng/dialog';
import {isPlatformBrowser} from '@angular/common';
import {Button} from 'primeng/button';
import {AuthService} from './auth.service';
-import {CookieService} from 'ngx-cookie-service';
+import {Router} from '@angular/router';
@Component({
selector: 'app-root',
@@ -23,8 +23,8 @@ export class AppComponent implements OnInit {
isSessionExpired: boolean = false;
constructor(@Inject(PLATFORM_ID) private platformId: object,
- private authService: AuthService,
- private cookieService: CookieService) {
+ protected authService: AuthService,
+ private router: Router,) {
}
isBrowser(): boolean {
@@ -34,6 +34,7 @@ export class AppComponent implements OnInit {
setSessionExpiredFalse(): void {
this.isSessionExpired = false;
this.authService.setSessionExpired(false);
+ this.router.navigate(['/logout']);
}
ngOnInit(): void {
diff --git a/src/app/app.config.ts b/src/app/app.config.ts
index a955765..becc995 100644
--- a/src/app/app.config.ts
+++ b/src/app/app.config.ts
@@ -5,6 +5,7 @@ import {routes} from './app.routes';
import {provideClientHydration} from '@angular/platform-browser';
import {provideHttpClient, withFetch} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
+import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
export const appConfig: ApplicationConfig = {
providers: [
@@ -12,5 +13,5 @@ export const appConfig: ApplicationConfig = {
provideRouter(routes),
provideClientHydration(),
provideHttpClient(withFetch()),
- importProvidersFrom([BrowserAnimationsModule])]
+ importProvidersFrom([BrowserAnimationsModule]), provideAnimationsAsync()]
};
diff --git a/src/app/auth.service.ts b/src/app/auth.service.ts
index 55196b9..3471c95 100644
--- a/src/app/auth.service.ts
+++ b/src/app/auth.service.ts
@@ -1,5 +1,4 @@
import {Injectable} from '@angular/core';
-import {CookieService} from 'ngx-cookie-service';
import {Author} from './models/author';
import {BehaviorSubject} from 'rxjs';
import {DateTime} from 'luxon';
@@ -11,7 +10,7 @@ export class AuthService {
private sessionExpiredSubject = new BehaviorSubject
(false);
sessionExpired$ = this.sessionExpiredSubject.asObservable();
- constructor(private cookieService: CookieService) {
+ constructor() {
this.checkSessionExpiration();
}
diff --git a/src/app/components/post-home/post-home.component.html b/src/app/components/post-home/post-home.component.html
index c5613d0..6aaabc2 100644
--- a/src/app/components/post-home/post-home.component.html
+++ b/src/app/components/post-home/post-home.component.html
@@ -5,7 +5,7 @@
{{ category }}
Publié le {{ date | date : "dd/MM/yyyy à HH:mm" }}
{{ description }}
-
+
@if (authorProfilePicture) {
{
this.successMessage("Mise à jour réussie", "Profil mit à jour avec succès");
this.updatedAuthorEvent.emit(author);
- this.cookieService.set('author', JSON.stringify(author));
+ sessionStorage.setItem('author', JSON.stringify(author));
this.router.navigate(['/']);
},
error: (err) => {
@@ -104,7 +102,7 @@ export class UpdateProfileFormComponent implements OnDestroy {
next: (author: Author) => {
this.successMessage("Mise à jour réussie", "Profil mit à jour avec succès");
this.updatedAuthorEvent.emit(author);
- this.cookieService.set('author', JSON.stringify(author));
+ sessionStorage.setItem('author', JSON.stringify(author));
this.router.navigate(['/']);
},
error: (err) => {
diff --git a/src/app/guards/admin.guard.ts b/src/app/guards/admin.guard.ts
index 5e90c8d..f9ac1b4 100644
--- a/src/app/guards/admin.guard.ts
+++ b/src/app/guards/admin.guard.ts
@@ -1,17 +1,13 @@
import {CanActivateFn, Router} from '@angular/router';
import {inject} from '@angular/core';
-import {CookieService} from 'ngx-cookie-service';
import {AuthService} from '../auth.service';
import {Role} from '../models/role';
export const adminGuard: CanActivateFn = (route, state) => {
const router = inject(Router);
- const cookieService = inject(CookieService);
const authService: AuthService = inject(AuthService);
-
- if ((authService.isAuthenticated() && JSON.parse(cookieService.get("author")).role !== Role.ADMIN) || !authService.isAuthenticated()) {
+ if ((authService.isAuthenticated() && JSON.parse(sessionStorage.getItem("author")!).role !== Role.ADMIN) || !authService.isAuthenticated()) {
router.navigate(['/']);
}
-
return true;
};
diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts
index 0d4456a..de721de 100644
--- a/src/app/guards/auth.guard.ts
+++ b/src/app/guards/auth.guard.ts
@@ -1,11 +1,9 @@
import {CanActivateFn, Router} from '@angular/router';
import {inject} from '@angular/core';
-import {CookieService} from 'ngx-cookie-service';
export const authGuard: CanActivateFn = (route, state) => {
const router = inject(Router);
- const cookieService = inject(CookieService);
- if (cookieService.check("author") || cookieService.check("token")) {
+ if (sessionStorage.getItem("author") !== null || sessionStorage.getItem("token") !== null) {
router.navigate(['/']);
}
diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts
index f056b75..09f044c 100644
--- a/src/app/pages/login/login.component.ts
+++ b/src/app/pages/login/login.component.ts
@@ -7,7 +7,6 @@ import {ToastModule} from 'primeng/toast';
import {MessageService} from 'primeng/api';
import {Author} from '../../models/author';
import {Subscription, switchMap} from 'rxjs';
-import {CookieService} from 'ngx-cookie-service';
import {HeaderComponent} from '../../components/header/header.component';
import {Router} from '@angular/router';
import {ConfigurationService} from '../../configuration.service';
diff --git a/src/app/pages/logout/logout.component.ts b/src/app/pages/logout/logout.component.ts
index b27b7d3..cf4634e 100644
--- a/src/app/pages/logout/logout.component.ts
+++ b/src/app/pages/logout/logout.component.ts
@@ -1,9 +1,7 @@
import {Component, OnInit} from '@angular/core';
-import {CookieService} from 'ngx-cookie-service';
import {HeaderComponent} from '../../components/header/header.component';
import {Router} from '@angular/router';
import {MessageService} from 'primeng/api';
-import {ConfigurationService} from '../../configuration.service';
@Component({
selector: 'app-logout',
@@ -14,19 +12,16 @@ import {ConfigurationService} from '../../configuration.service';
templateUrl: './logout.component.html',
styleUrl: './logout.component.css'
})
-export class LogoutComponent implements OnInit{
+export class LogoutComponent implements OnInit {
+
+ constructor(private messageService: MessageService,
+ private router: Router) {
+ }
- constructor(private cookieService: CookieService,
- private messageService: MessageService,
- private router: Router,
- private configurationService: ConfigurationService,) { }
ngOnInit(): void {
- const routes: string[] = ['/', '/login', '/register', '/logout', '/profile', '/post', '/new-post', '/admin']
- Object.keys(this.cookieService.getAll()).forEach(key => {
- routes.forEach(route => {
- this.cookieService.delete(key, route, this.configurationService.getDomain());
- })
- });
+ sessionStorage.removeItem("author");
+ sessionStorage.removeItem("token");
+ sessionStorage.removeItem("token-expiration-date");
this.router.navigate(['/']).then(() => this.successMessage('Déconnexion', 'Vous avez été deconnecté avec succès'));
}
diff --git a/src/index.html b/src/index.html
index 127cabd..84c9c6c 100644
--- a/src/index.html
+++ b/src/index.html
@@ -7,9 +7,11 @@
+
+
-
+