From 50179801b11510ddd9d4464c44ebdd47cb56b8b3 Mon Sep 17 00:00:00 2001 From: Guams Date: Sun, 16 Feb 2025 01:39:00 +0100 Subject: [PATCH] =?UTF-8?q?update=20des=20cookies=20pour=20le=20d=C3=A9plo?= =?UTF-8?q?iement=20sur=20le=20domaine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular.json | 4 +++- configuration.json | 1 + src/app/configuration.service.ts | 4 ++++ src/app/pages/login/login.component.ts | 7 +++++-- src/app/pages/logout/logout.component.ts | 2 +- src/index.html | 26 ++++++++++++++---------- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/angular.json b/angular.json index e537cd1..faaad1f 100644 --- a/angular.json +++ b/angular.json @@ -64,7 +64,9 @@ "serve": { "options": { "host": "0.0.0.0", - "allowedHosts": ["abonentendeur.guams.fr"] + "allowedHosts": [ + "abonentendeur.guams.fr" + ] }, "builder": "@angular-devkit/build-angular:dev-server", "configurations": { diff --git a/configuration.json b/configuration.json index 16da39b..75213b2 100644 --- a/configuration.json +++ b/configuration.json @@ -1,4 +1,5 @@ { + "domain": "localhost", "serverAddress": "localhost", "apiURL": "http://localhost:8080/api", "tokenTTL": 36000000 diff --git a/src/app/configuration.service.ts b/src/app/configuration.service.ts index dc1199c..b9d8311 100644 --- a/src/app/configuration.service.ts +++ b/src/app/configuration.service.ts @@ -6,6 +6,10 @@ import * as config from '../../configuration.json' }) export class ConfigurationService { + getDomain(): string { + return config.domain; + } + getApiUrl(): string { return config.apiURL } diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index 8825cf4..65e14a7 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -45,8 +45,9 @@ export class LoginComponent implements OnDestroy { ( this.authorService.login(this.name, this.password).pipe( switchMap((tokenObj: any) => { - this.cookieService.delete('token', '/', this.configurationService.getServerAddress()) + this.cookieService.delete('token', '/', this.configurationService.getDomain()) this.cookieService.set("token", tokenObj.token, { + domain: this.configurationService.getDomain(), secure: true, path: '/' }); @@ -54,11 +55,13 @@ export class LoginComponent implements OnDestroy { })) .subscribe({ next: (author: Author) => { - this.cookieService.delete('author', '/', this.configurationService.getServerAddress()) + this.cookieService.delete('author', '/', this.configurationService.getDomain()) this.cookieService.set("author", JSON.stringify(author), { + domain: this.configurationService.getDomain(), secure : true, path: '/' }); this.cookieService.set('token-expiration-date', DateTime.now().plus({millisecond: this.configurationService.getTokenTTL()}).toISO(), { + domain: this.configurationService.getDomain(), secure: true, path: '/', }) diff --git a/src/app/pages/logout/logout.component.ts b/src/app/pages/logout/logout.component.ts index 3d9fb28..b27b7d3 100644 --- a/src/app/pages/logout/logout.component.ts +++ b/src/app/pages/logout/logout.component.ts @@ -24,7 +24,7 @@ export class LogoutComponent implements OnInit{ 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.getServerAddress()); + this.cookieService.delete(key, route, this.configurationService.getDomain()); }) }); 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 ac9c996..127cabd 100644 --- a/src/index.html +++ b/src/index.html @@ -1,5 +1,6 @@ + A BON ENTENDEUR @@ -7,17 +8,20 @@ + - - + + +