@ng-vagabond-lab/ng-dsv 0.1.73 → 0.1.74
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.
|
@@ -23,11 +23,13 @@ class AuthComponent {
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
effect(() => {
|
|
26
|
-
if (this.
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {
|
|
27
|
+
if (this.authService.userConnected() === null) {
|
|
28
|
+
this.authGoogleService.loginWithGoogle();
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.initMember.emit(this.authService.userConnected()?.user?.id);
|
|
32
|
+
}
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
35
|
}
|
|
@@ -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 {\n Component,\n effect,\n inject,\n output\n} from '@angular/core';\nimport { ID } from '@ng-vagabond-lab/ng-dsv/api';\nimport {\n ModalAlertComponent,\n ModalButtonComponent,\n} 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 readonly initMember = output<ID>();\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.authService.userConnected() === null) {\n this.authGoogleService.loginWithGoogle();\n } else {\n this.initMember.emit(this.authService.userConnected()?.user?.id);\n }\n });\n }\n\n logout() {\n this.authService.logout();\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 [src]=\"authService.userConnected()?.user?.avatar\" alt=\"profile\" />\n <dsv-modal-button id=\"logout\" icon=\"ri-logout-box-line\" />\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 = (\n route: ActivatedRouteSnapshot,\n) => {\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 authService.loginFromCache();\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 { inject, Injectable, signal } from '@angular/core';\nimport { ApiService } from '@ng-vagabond-lab/ng-dsv/api';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { StorageService } from '@ng-vagabond-lab/ng-dsv/storage';\nimport { UserConnectedDto } from '../dto/user.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n apiService = inject(ApiService);\n toastService = inject(ToastService);\n storageService = inject(StorageService);\n\n userConnected = signal<UserConnectedDto | null>(null);\n\n googleLogin(credential: string) {\n this.apiService.post<UserConnectedDto>(\n 'auth/google-identity-connect',\n {\n googleToken: credential,\n },\n (data) => {\n this.storageService.setItem('user-connected', JSON.stringify(data));\n this.userConnected.set(data);\n this.toastService.showToast({\n type: 'success',\n text: 'Connexion réussie',\n });\n }\n );\n }\n\n loginFromCache() {\n const userConnected =\n typeof window !== 'undefined' &&\n JSON.parse(this.storageService?.getItem('user-connected')!);\n this.userConnected.set(userConnected);\n this.apiService.info('userConnected', userConnected);\n return userConnected;\n }\n\n logout() {\n this.storageService?.removeItem('user-connected');\n this.userConnected.set(null);\n this.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 initGoogle: boolean = false;\n\n initGoogleAuth(googleButtonid: string = 'google-signin-button') {\n //if (!this.initGoogle) {\n this.initGoogle = true;\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(\n document.getElementById(googleButtonid)!,\n {\n theme: 'outline',\n size: 'medium',\n type: 'icon',\n }\n );\n //}\n }\n\n handleCredentialResponse(response: { credential: string }) {\n this.authService.googleLogin(response.credential);\n }\n\n decodeJwtToken(token: string) {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const jsonPayload = decodeURIComponent(\n atob(base64)\n .split('')\n .map(function (c) {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join('')\n );\n return JSON.parse(jsonPayload);\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 (userRoles?.find(userRole => userRole['roles' as keyof ApiDto]?.toString().includes(role) || userRole['name' as keyof ApiDto] === role)) {\n find = true;\n }\n });\n return find;\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;MAsBa,aAAa,CAAA;AACf,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;IAEzC,UAAU,GAAG,MAAM,EAAM;AAElC,IAAA,WAAA,GAAA;QACE,MAAM,CAAC,MAAK;AACV,YAAA,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC,iBAAiB,EAAE,EAAE;AAC7E,gBAAA,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE;AACvC,gBAAA,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE;YACnC;AACF,QAAA,CAAC,CAAC;QACF,MAAM,CAAC,MAAK;YACV,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;AAC7C,gBAAA,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O,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAChC;IAEA,eAAe,GAAA;AACb,QAAA,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE;IAC7B;uGA5CW,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,cAFhB,MAAM,EAAA,CAAA;;2FAEP,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAH7B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,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,IAAI,IAAG;AACrB,QAAA,IAAI,SAAS,EAAE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAuB,CAAC,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAAC,EAAE;YACxI,IAAI,GAAG,IAAI;QACf;AACJ,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,IAAI;AACf;;ACXA;;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/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 {\n Component,\n effect,\n inject,\n output\n} from '@angular/core';\nimport { ID } from '@ng-vagabond-lab/ng-dsv/api';\nimport {\n ModalAlertComponent,\n ModalButtonComponent,\n} 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 readonly initMember = output<ID>();\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.loginWithGoogle();\n } else {\n this.initMember.emit(this.authService.userConnected()?.user?.id);\n }\n }\n });\n }\n\n logout() {\n this.authService.logout();\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 [src]=\"authService.userConnected()?.user?.avatar\" alt=\"profile\" />\n <dsv-modal-button id=\"logout\" icon=\"ri-logout-box-line\" />\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 = (\n route: ActivatedRouteSnapshot,\n) => {\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 authService.loginFromCache();\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 { inject, Injectable, signal } from '@angular/core';\nimport { ApiService } from '@ng-vagabond-lab/ng-dsv/api';\nimport { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';\nimport { StorageService } from '@ng-vagabond-lab/ng-dsv/storage';\nimport { UserConnectedDto } from '../dto/user.dto';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class AuthService {\n apiService = inject(ApiService);\n toastService = inject(ToastService);\n storageService = inject(StorageService);\n\n userConnected = signal<UserConnectedDto | null>(null);\n\n googleLogin(credential: string) {\n this.apiService.post<UserConnectedDto>(\n 'auth/google-identity-connect',\n {\n googleToken: credential,\n },\n (data) => {\n this.storageService.setItem('user-connected', JSON.stringify(data));\n this.userConnected.set(data);\n this.toastService.showToast({\n type: 'success',\n text: 'Connexion réussie',\n });\n }\n );\n }\n\n loginFromCache() {\n const userConnected =\n typeof window !== 'undefined' &&\n JSON.parse(this.storageService?.getItem('user-connected')!);\n this.userConnected.set(userConnected);\n this.apiService.info('userConnected', userConnected);\n return userConnected;\n }\n\n logout() {\n this.storageService?.removeItem('user-connected');\n this.userConnected.set(null);\n this.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 initGoogle: boolean = false;\n\n initGoogleAuth(googleButtonid: string = 'google-signin-button') {\n //if (!this.initGoogle) {\n this.initGoogle = true;\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(\n document.getElementById(googleButtonid)!,\n {\n theme: 'outline',\n size: 'medium',\n type: 'icon',\n }\n );\n //}\n }\n\n handleCredentialResponse(response: { credential: string }) {\n this.authService.googleLogin(response.credential);\n }\n\n decodeJwtToken(token: string) {\n const base64Url = token.split('.')[1];\n const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');\n const jsonPayload = decodeURIComponent(\n atob(base64)\n .split('')\n .map(function (c) {\n return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);\n })\n .join('')\n );\n return JSON.parse(jsonPayload);\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 (userRoles?.find(userRole => userRole['roles' as keyof ApiDto]?.toString().includes(role) || userRole['name' as keyof ApiDto] === role)) {\n find = true;\n }\n });\n return find;\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;MAsBa,aAAa,CAAA;AACf,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC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