@ng-vagabond-lab/ng-dsv 0.1.88 → 0.1.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,9 @@ import { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';
6
6
  import { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';
7
7
  import { ApiService } from '@ng-vagabond-lab/ng-dsv/api';
8
8
  import { Router } from '@angular/router';
9
+ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
10
+ import { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';
11
+ import { catchError, throwError, switchMap } from 'rxjs';
9
12
 
10
13
  class AuthComponent {
11
14
  authService = inject(AuthService);
@@ -15,16 +18,15 @@ class AuthComponent {
15
18
  callbackInitMember = output();
16
19
  callbackLogout = output();
17
20
  constructor() {
18
- // effect(() => {
19
- // if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {
20
- // this.authGoogleService.initGoogleAuth();
21
- // //this.authService.loginFromCache();
22
- // }
23
- // });
21
+ effect(() => {
22
+ if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {
23
+ this.authGoogleService.initGoogleAuth();
24
+ this.authService.refreshToken();
25
+ }
26
+ });
24
27
  effect(() => {
25
28
  if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {
26
29
  if (this.authService.userConnected() === null) {
27
- this.authGoogleService.initGoogleAuth();
28
30
  this.authGoogleService.loginWithGoogle();
29
31
  }
30
32
  else {
@@ -65,14 +67,57 @@ const authGuard = (route) => {
65
67
  return false;
66
68
  };
67
69
 
70
+ const authInterceptor = (req, next) => {
71
+ const httpClient = inject(HttpClient);
72
+ const authService = inject(AuthService);
73
+ const toastService = inject(ToastService);
74
+ return next(getToken(req, authService)).pipe(catchError((error) => {
75
+ if (error instanceof HttpErrorResponse &&
76
+ !req.url.includes('auth/') &&
77
+ req.url.includes(authService.apiService.baseUrl) &&
78
+ error.status === 401) {
79
+ return handle401Error(httpClient, authService, req, next);
80
+ }
81
+ console.error(error);
82
+ toastService.showToast({
83
+ type: 'error',
84
+ text: error.error.debugMessage ?? error.error.message ?? error.message,
85
+ });
86
+ return throwError(() => error);
87
+ }));
88
+ };
89
+ const getToken = (req, authService) => {
90
+ const jwt = authService.userToken();
91
+ if (!req.url.includes('/auth/') && req.url.includes(authService.apiService.baseUrl) && jwt) {
92
+ const headers = req.headers.set('Authorization', `Bearer ${jwt}`);
93
+ return req.clone({
94
+ headers,
95
+ });
96
+ }
97
+ return req;
98
+ };
99
+ const handle401Error = (httpClient, authService, request, next) => {
100
+ return httpClient
101
+ .post(authService.apiService.baseUrl + '/auth/refresh-token', {}, { withCredentials: true })
102
+ .pipe(switchMap((response) => {
103
+ authService.initUser(response);
104
+ return next(getToken(request, authService));
105
+ }));
106
+ };
107
+
68
108
  class AuthService {
69
109
  apiService = inject(ApiService);
70
110
  userConnected = signal(null, ...(ngDevMode ? [{ debugName: "userConnected" }] : /* istanbul ignore next */ []));
111
+ userToken = signal('', ...(ngDevMode ? [{ debugName: "userToken" }] : /* istanbul ignore next */ []));
71
112
  constructor() {
72
113
  effect(() => {
73
114
  this.userConnected.set(this.apiService.userConnected());
74
115
  });
75
116
  }
117
+ initUser(user = null) {
118
+ this.userConnected.set(user);
119
+ this.userToken.set(user?.['jwt'] ?? '');
120
+ }
76
121
  googleLogin(credential) {
77
122
  this.apiService.post('auth/google-identity-connect', {
78
123
  googleToken: credential,
@@ -84,12 +129,17 @@ class AuthService {
84
129
  });
85
130
  }, true);
86
131
  }
132
+ refreshToken() {
133
+ this.apiService.post('auth/refresh-token', {}, (data) => this.initUser(data), true);
134
+ }
87
135
  logout() {
88
- this.apiService.initUser();
89
- this.apiService.toastService.showToast({
90
- type: 'success',
91
- text: 'Déconnexion réussie',
92
- });
136
+ this.apiService.post('auth/logout', {}, () => {
137
+ this.apiService.initUser();
138
+ this.apiService.toastService.showToast({
139
+ type: 'success',
140
+ text: 'Déconnexion réussie',
141
+ });
142
+ }, true);
93
143
  }
94
144
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: AuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
95
145
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: AuthService, providedIn: 'root' });
@@ -147,5 +197,5 @@ const hasRole = (roles, userRoles) => {
147
197
  * Generated bundle index. Do not edit.
148
198
  */
149
199
 
150
- export { AuthComponent, AuthGoogleService, AuthService, authGuard, hasRole };
200
+ export { AuthComponent, AuthGoogleService, AuthService, authGuard, authInterceptor, hasRole };
151
201
  //# sourceMappingURL=ng-vagabond-lab-ng-dsv-modules-auth.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ng-vagabond-lab-ng-dsv-modules-auth.mjs","sources":["../../../projects/ng-dsv/modules/auth/component/auth.component.ts","../../../projects/ng-dsv/modules/auth/component/auth.component.html","../../../projects/ng-dsv/modules/auth/guard/auth.guard.ts","../../../projects/ng-dsv/modules/auth/service/auth.service.ts","../../../projects/ng-dsv/modules/auth/service/auth.google.service.ts","../../../projects/ng-dsv/modules/auth/utils/auth.utils.ts","../../../projects/ng-dsv/modules/auth/ng-vagabond-lab-ng-dsv-modules-auth.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\nimport { Component, effect, inject, output } from '@angular/core';\nimport { ID } from '@ng-vagabond-lab/ng-dsv/api';\nimport { ModalAlertComponent, ModalButtonComponent } from '@ng-vagabond-lab/ng-dsv/ds/modal';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthGoogleService, AuthService } from '../public-api';\n\n@Component({\n selector: 'dsv-auth',\n imports: [CommonModule, ModalButtonComponent, ModalAlertComponent],\n templateUrl: './auth.component.html',\n styleUrls: ['./auth.component.scss'],\n})\nexport class AuthComponent {\n readonly authService = inject(AuthService);\n readonly authGoogleService = inject(AuthGoogleService);\n readonly environmentService = inject(EnvironmentService);\n readonly platformService = inject(PlatformService);\n\n callbackInitMember = output<ID>();\n callbackLogout = output<void>();\n\n constructor() {\n // effect(() => {\n // if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n // this.authGoogleService.initGoogleAuth();\n // //this.authService.loginFromCache();\n // }\n // });\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n if (this.authService.userConnected() === null) {\n this.authGoogleService.initGoogleAuth();\n this.authGoogleService.loginWithGoogle();\n } else {\n this.callbackInitMember.emit(this.authService.userConnected()?.user?.id);\n }\n }\n });\n }\n\n logout() {\n this.authService.logout();\n this.callbackLogout.emit();\n }\n}\n","<div class=\"auth-button\">\n <button\n id=\"google-signin-button\"\n [class.hidden]=\"authService.userConnected() !== null\"\n ></button>\n</div>\n\n@if (authService.userConnected()) {\n <div class=\"profile\">\n <img\n [src]=\"authService.userConnected()?.user?.avatar\"\n alt=\"profile\"\n />\n <dsv-modal-button\n id=\"logout\"\n icon=\"ri-logout-box-line\"\n />\n </div>\n <dsv-modal-alert\n id=\"logout\"\n title=\"Déconnexion\"\n text=\"Voulez-vous vraiment vous déconnecter ?\"\n button=\"Oui\"\n buttonClose=\"Non\"\n (callback)=\"logout()\"\n ></dsv-modal-alert>\n}\n","import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthService, hasRole } from '../public-api';\n\nexport const authGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {\n const platformService = inject(PlatformService);\n\n if (!platformService.isPlatformBrowser()) {\n return true;\n }\n\n const authService = inject(AuthService);\n const router = inject(Router);\n\n const requiredRole = route.data['role'];\n\n if (!requiredRole) {\n console.warn('No role specified in route data.');\n return false;\n }\n\n const profiles = authService.userConnected()?.user?.profiles;\n if (hasRole(requiredRole, profiles)) {\n return true;\n }\n\n router.navigate(['/']);\n return false;\n};\n","import { effect, inject, Injectable, signal } from '@angular/core';\nimport { ApiService, JSONObject } from '@ng-vagabond-lab/ng-dsv/api';\nimport { UserConnectedDto } from '../dto/user.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n apiService = inject(ApiService);\n\n userConnected = signal<UserConnectedDto | null>(null);\n\n constructor() {\n effect(() => {\n this.userConnected.set(this.apiService.userConnected() as UserConnectedDto);\n });\n }\n\n googleLogin(credential: string) {\n this.apiService.post<UserConnectedDto>(\n 'auth/google-identity-connect',\n {\n googleToken: credential,\n },\n (data) => {\n this.apiService.initUser(data as JSONObject);\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Connexion réussie',\n });\n },\n true,\n );\n }\n\n logout() {\n this.apiService.initUser();\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Déconnexion réussie',\n });\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { AuthService } from './auth.service';\n\ndeclare const google: any;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthGoogleService {\n private readonly authService = inject(AuthService);\n private readonly environmentService = inject(EnvironmentService);\n\n initGoogleAuth(googleButtonid: string = 'google-signin-button') {\n google.accounts.id.initialize({\n client_id: this.environmentService.env()?.GOOGLE_CLIENT_ID,\n callback: this.handleCredentialResponse.bind(this),\n });\n google.accounts.id.renderButton(document.getElementById(googleButtonid)!, {\n theme: 'outline',\n size: 'medium',\n type: 'icon',\n });\n }\n\n handleCredentialResponse(response: { credential: string }) {\n this.authService.googleLogin(response.credential);\n }\n\n loginWithGoogle() {\n google.accounts.id.prompt();\n }\n}\n","import { ApiDto } from '@ng-vagabond-lab/ng-dsv/api';\n\nexport const hasRole = (roles: string, userRoles?: ApiDto[]) => {\n const roleSplit = roles.split(',');\n let find = false;\n roleSplit.forEach((role) => {\n if (\n userRoles?.find(\n (userRole) =>\n userRole['roles' as keyof ApiDto]?.toString().includes(role) ||\n userRole['name' as keyof ApiDto] === role,\n )\n ) {\n find = true;\n }\n });\n return find;\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;MAca,aAAa,CAAA;AACb,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC7C,IAAA,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AAC/C,IAAA,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IAElD,kBAAkB,GAAG,MAAM,EAAM;IACjC,cAAc,GAAG,MAAM,EAAQ;AAE/B,IAAA,WAAA,GAAA;;;;;;;QAOI,MAAM,CAAC,MAAK;AACR,YAAA,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC,iBAAiB,EAAE,EAAE;gBAC3E,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;AAC3C,oBAAA,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE;AACvC,oBAAA,IAAI,CAAC,iBAAiB,CAAC,eAAe,EAAE;gBAC5C;qBAAO;AACH,oBAAA,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;gBAC5E;YACJ;AACJ,QAAA,CAAC,CAAC;IACN;IAEA,MAAM,GAAA;AACF,QAAA,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;AACzB,QAAA,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE;IAC9B;uGA/BS,aAAa,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAb,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA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A,EAAA,EAAA,IAAA,EAAA,iBAAiB,cAFd,MAAM,EAAA,CAAA;;2FAET,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAH7B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE,MAAM;AACrB,iBAAA;;;MCNY,OAAO,GAAG,CAAC,KAAa,EAAE,SAAoB,KAAI;IAC3D,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;IAClC,IAAI,IAAI,GAAG,KAAK;AAChB,IAAA,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;QACvB,IACI,SAAS,EAAE,IAAI,CACX,CAAC,QAAQ,KACL,QAAQ,CAAC,OAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC5D,YAAA,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAChD,EACH;YACE,IAAI,GAAG,IAAI;QACf;AACJ,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,IAAI;AACf;;ACjBA;;AAEG;;;;"}
1
+ {"version":3,"file":"ng-vagabond-lab-ng-dsv-modules-auth.mjs","sources":["../../../projects/ng-dsv/modules/auth/component/auth.component.ts","../../../projects/ng-dsv/modules/auth/component/auth.component.html","../../../projects/ng-dsv/modules/auth/guard/auth.guard.ts","../../../projects/ng-dsv/modules/auth/interceptor/auth.interceptor.ts","../../../projects/ng-dsv/modules/auth/service/auth.service.ts","../../../projects/ng-dsv/modules/auth/service/auth.google.service.ts","../../../projects/ng-dsv/modules/auth/utils/auth.utils.ts","../../../projects/ng-dsv/modules/auth/ng-vagabond-lab-ng-dsv-modules-auth.ts"],"sourcesContent":["import { CommonModule } from '@angular/common';\nimport { Component, effect, inject, output } from '@angular/core';\nimport { ID } from '@ng-vagabond-lab/ng-dsv/api';\nimport { ModalAlertComponent, ModalButtonComponent } from '@ng-vagabond-lab/ng-dsv/ds/modal';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthGoogleService, AuthService } from '../public-api';\n\n@Component({\n selector: 'dsv-auth',\n imports: [CommonModule, ModalButtonComponent, ModalAlertComponent],\n templateUrl: './auth.component.html',\n styleUrls: ['./auth.component.scss'],\n})\nexport class AuthComponent {\n readonly authService = inject(AuthService);\n readonly authGoogleService = inject(AuthGoogleService);\n readonly environmentService = inject(EnvironmentService);\n readonly platformService = inject(PlatformService);\n\n callbackInitMember = output<ID>();\n callbackLogout = output<void>();\n\n constructor() {\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n this.authGoogleService.initGoogleAuth();\n this.authService.refreshToken();\n }\n });\n effect(() => {\n if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {\n if (this.authService.userConnected() === null) {\n this.authGoogleService.loginWithGoogle();\n } else {\n this.callbackInitMember.emit(this.authService.userConnected()?.user?.id);\n }\n }\n });\n }\n\n logout() {\n this.authService.logout();\n this.callbackLogout.emit();\n }\n}\n","<div class=\"auth-button\">\n <button\n id=\"google-signin-button\"\n [class.hidden]=\"authService.userConnected() !== null\"\n ></button>\n</div>\n\n@if (authService.userConnected()) {\n <div class=\"profile\">\n <img\n [src]=\"authService.userConnected()?.user?.avatar\"\n alt=\"profile\"\n />\n <dsv-modal-button\n id=\"logout\"\n icon=\"ri-logout-box-line\"\n />\n </div>\n <dsv-modal-alert\n id=\"logout\"\n title=\"Déconnexion\"\n text=\"Voulez-vous vraiment vous déconnecter ?\"\n button=\"Oui\"\n buttonClose=\"Non\"\n (callback)=\"logout()\"\n ></dsv-modal-alert>\n}\n","import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, CanActivateFn, Router } from '@angular/router';\nimport { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\nimport { AuthService, hasRole } from '../public-api';\n\nexport const authGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {\n const platformService = inject(PlatformService);\n\n if (!platformService.isPlatformBrowser()) {\n return true;\n }\n\n const authService = inject(AuthService);\n const router = inject(Router);\n\n const requiredRole = route.data['role'];\n\n if (!requiredRole) {\n console.warn('No role specified in route data.');\n return false;\n }\n\n const profiles = authService.userConnected()?.user?.profiles;\n if (hasRole(requiredRole, profiles)) {\n return true;\n }\n\n router.navigate(['/']);\n return false;\n};\n","import { HttpClient, HttpErrorResponse, HttpHandlerFn, HttpRequest } from '@angular/common/http';\nimport { inject } from '@angular/core';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { catchError, switchMap, throwError } from 'rxjs';\nimport { AuthService } from '../public-api';\n\nexport const authInterceptor = (req: HttpRequest<unknown>, next: HttpHandlerFn) => {\n const httpClient = inject(HttpClient);\n const authService = inject(AuthService);\n const toastService = inject(ToastService);\n\n return next(getToken(req, authService)).pipe(\n catchError((error) => {\n if (\n error instanceof HttpErrorResponse &&\n !req.url.includes('auth/') &&\n req.url.includes(authService.apiService.baseUrl) &&\n error.status === 401\n ) {\n return handle401Error(httpClient, authService, req, next);\n }\n\n console.error(error);\n\n toastService.showToast({\n type: 'error',\n text: error.error.debugMessage ?? error.error.message ?? error.message,\n });\n\n return throwError(() => error);\n }),\n );\n};\n\nconst getToken = <T>(req: HttpRequest<T>, authService: AuthService) => {\n const jwt = authService.userToken();\n if (!req.url.includes('/auth/') && req.url.includes(authService.apiService.baseUrl) && jwt) {\n const headers = req.headers.set('Authorization', `Bearer ${jwt}`);\n\n return req.clone({\n headers,\n });\n }\n return req;\n};\n\nconst handle401Error = <T>(\n httpClient: HttpClient,\n authService: AuthService,\n request: HttpRequest<T>,\n next: HttpHandlerFn,\n) => {\n return httpClient\n .post(authService.apiService.baseUrl + '/auth/refresh-token', {}, { withCredentials: true })\n .pipe(\n switchMap((response) => {\n authService.initUser(response);\n return next(getToken(request, authService));\n }),\n );\n};\n","import { effect, inject, Injectable, signal } from '@angular/core';\nimport { ApiService, JSONObject } from '@ng-vagabond-lab/ng-dsv/api';\nimport { UserConnectedDto } from '../dto/user.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n apiService = inject(ApiService);\n\n userConnected = signal<UserConnectedDto | null>(null);\n userToken = signal<string>('');\n\n constructor() {\n effect(() => {\n this.userConnected.set(this.apiService.userConnected() as UserConnectedDto);\n });\n }\n\n initUser(user: UserConnectedDto | null = null) {\n this.userConnected.set(user);\n this.userToken.set(user?.['jwt' as keyof JSONObject] ?? '');\n }\n\n googleLogin(credential: string) {\n this.apiService.post<UserConnectedDto>(\n 'auth/google-identity-connect',\n {\n googleToken: credential,\n },\n (data) => {\n this.apiService.initUser(data as JSONObject);\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Connexion réussie',\n });\n },\n true,\n );\n }\n\n refreshToken() {\n this.apiService.post<UserConnectedDto>('auth/refresh-token', {}, (data) => this.initUser(data), true);\n }\n\n logout() {\n this.apiService.post<UserConnectedDto>(\n 'auth/logout',\n {},\n () => {\n this.apiService.initUser();\n this.apiService.toastService.showToast({\n type: 'success',\n text: 'Déconnexion réussie',\n });\n },\n true,\n );\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';\nimport { AuthService } from './auth.service';\n\ndeclare const google: any;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthGoogleService {\n private readonly authService = inject(AuthService);\n private readonly environmentService = inject(EnvironmentService);\n\n initGoogleAuth(googleButtonid: string = 'google-signin-button') {\n google.accounts.id.initialize({\n client_id: this.environmentService.env()?.GOOGLE_CLIENT_ID,\n callback: this.handleCredentialResponse.bind(this),\n });\n google.accounts.id.renderButton(document.getElementById(googleButtonid)!, {\n theme: 'outline',\n size: 'medium',\n type: 'icon',\n });\n }\n\n handleCredentialResponse(response: { credential: string }) {\n this.authService.googleLogin(response.credential);\n }\n\n loginWithGoogle() {\n google.accounts.id.prompt();\n }\n}\n","import { ApiDto } from '@ng-vagabond-lab/ng-dsv/api';\n\nexport const hasRole = (roles: string, userRoles?: ApiDto[]) => {\n const roleSplit = roles.split(',');\n let find = false;\n roleSplit.forEach((role) => {\n if (\n userRoles?.find(\n (userRole) =>\n userRole['roles' as keyof ApiDto]?.toString().includes(role) ||\n userRole['name' as keyof ApiDto] === role,\n )\n ) {\n find = true;\n }\n });\n return find;\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;;MAca,aAAa,CAAA;AACb,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC7C,IAAA,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AAC/C,IAAA,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;IAElD,kBAAkB,GAAG,MAAM,EAAM;IACjC,cAAc,GAAG,MAAM,EAAQ;AAE/B,IAAA,WAAA,GAAA;QACI,MAAM,CAAC,MAAK;AACR,YAAA,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC,iBAAiB,EAAE,EAAE;AAC3E,gBAAA,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE;AACvC,gBAAA,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE;YACnC;AACJ,QAAA,CAAC,CAAC;QACF,MAAM,CAAC,MAAK;AACR,YAAA,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC,iBAAiB,EAAE,EAAE;gBAC3E,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;AAC3C,oBAAA,IAAI,CAAC,iBAAiB,CAAC,eAAe,EAAE;gBAC5C;qBAAO;AACH,oBAAA,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC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AAA,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE;IAC/B;uGAtBS,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAjB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,cAFd,MAAM,EAAA,CAAA;;2FAET,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAH7B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,UAAU,EAAE,MAAM;AACrB,iBAAA;;;MCNY,OAAO,GAAG,CAAC,KAAa,EAAE,SAAoB,KAAI;IAC3D,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;IAClC,IAAI,IAAI,GAAG,KAAK;AAChB,IAAA,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,KAAI;QACvB,IACI,SAAS,EAAE,IAAI,CACX,CAAC,QAAQ,KACL,QAAQ,CAAC,OAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC5D,YAAA,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAChD,EACH;YACE,IAAI,GAAG,IAAI;QACf;AACJ,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,IAAI;AACf;;ACjBA;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-vagabond-lab/ng-dsv",
3
- "version": "0.1.88",
3
+ "version": "0.1.89",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^20.0.0",
6
6
  "@angular/core": "^20.0.0"
@@ -3,6 +3,9 @@ import { ID, BaseUserConnectedDto, ApiDto, ApiService } from '@ng-vagabond-lab/n
3
3
  import { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';
4
4
  import { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';
5
5
  import { CanActivateFn } from '@angular/router';
6
+ import * as rxjs from 'rxjs';
7
+ import * as _angular_common_http from '@angular/common/http';
8
+ import { HttpRequest, HttpHandlerFn } from '@angular/common/http';
6
9
 
7
10
  declare class AuthComponent {
8
11
  readonly authService: AuthService;
@@ -28,7 +31,6 @@ interface UserDto extends ApiDto {
28
31
  interface UserConnectedDto extends BaseUserConnectedDto {
29
32
  googleToken?: string;
30
33
  jwt?: string;
31
- jwtRefresh?: string;
32
34
  user?: UserDto;
33
35
  }
34
36
  interface GoogleRequest {
@@ -37,6 +39,8 @@ interface GoogleRequest {
37
39
 
38
40
  declare const authGuard: CanActivateFn;
39
41
 
42
+ declare const authInterceptor: (req: HttpRequest<unknown>, next: HttpHandlerFn) => rxjs.Observable<_angular_common_http.HttpEvent<unknown>>;
43
+
40
44
  declare class AuthGoogleService {
41
45
  private readonly authService;
42
46
  private readonly environmentService;
@@ -52,8 +56,11 @@ declare class AuthGoogleService {
52
56
  declare class AuthService {
53
57
  apiService: ApiService;
54
58
  userConnected: i0.WritableSignal<UserConnectedDto | null>;
59
+ userToken: i0.WritableSignal<string>;
55
60
  constructor();
61
+ initUser(user?: UserConnectedDto | null): void;
56
62
  googleLogin(credential: string): void;
63
+ refreshToken(): void;
57
64
  logout(): void;
58
65
  static ɵfac: i0.ɵɵFactoryDeclaration<AuthService, never>;
59
66
  static ɵprov: i0.ɵɵInjectableDeclaration<AuthService>;
@@ -61,5 +68,5 @@ declare class AuthService {
61
68
 
62
69
  declare const hasRole: (roles: string, userRoles?: ApiDto[]) => boolean;
63
70
 
64
- export { AuthComponent, AuthGoogleService, AuthService, authGuard, hasRole };
71
+ export { AuthComponent, AuthGoogleService, AuthService, authGuard, authInterceptor, hasRole };
65
72
  export type { GoogleRequest, UserConnectedDto, UserDto };