@ng-vagabond-lab/ng-dsv 0.1.38 → 0.1.40
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.
|
@@ -13,20 +13,19 @@ class AuthComponent {
|
|
|
13
13
|
authGoogleService = inject(AuthGoogleService);
|
|
14
14
|
authService = inject(AuthService);
|
|
15
15
|
environmentService = inject(EnvironmentService);
|
|
16
|
+
platformService = inject(PlatformService);
|
|
16
17
|
initMember = output();
|
|
17
18
|
constructor() {
|
|
18
19
|
effect(() => {
|
|
19
|
-
if (this.
|
|
20
|
-
this.authGoogleService.loginWithGoogle();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
this.initMember.emit(this.authService.userConnected()?.user?.id);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
effect(() => {
|
|
27
|
-
if (this.environmentService.env()) {
|
|
20
|
+
if (this.environmentService.env() && this.platformService.isPlatformBrowser()) {
|
|
28
21
|
this.authService.loginFromCache();
|
|
29
22
|
this.authGoogleService.initGoogleAuth();
|
|
23
|
+
if (this.authService.userConnected() === null) {
|
|
24
|
+
this.authGoogleService.loginWithGoogle();
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.initMember.emit(this.authService.userConnected()?.user?.id);
|
|
28
|
+
}
|
|
30
29
|
}
|
|
31
30
|
});
|
|
32
31
|
}
|
|
@@ -107,9 +106,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.5", ngImpor
|
|
|
107
106
|
class AuthGoogleService {
|
|
108
107
|
authService = inject(AuthService);
|
|
109
108
|
environmentService = inject(EnvironmentService);
|
|
110
|
-
|
|
109
|
+
initGoogle = false;
|
|
111
110
|
initGoogleAuth() {
|
|
112
|
-
if (this.
|
|
111
|
+
if (!this.initGoogle) {
|
|
112
|
+
this.initGoogle = true;
|
|
113
113
|
google.accounts.id.initialize({
|
|
114
114
|
client_id: this.environmentService.env()?.GOOGLE_CLIENT_ID,
|
|
115
115
|
callback: this.handleCredentialResponse.bind(this),
|
|
@@ -136,9 +136,7 @@ class AuthGoogleService {
|
|
|
136
136
|
return JSON.parse(jsonPayload);
|
|
137
137
|
}
|
|
138
138
|
loginWithGoogle() {
|
|
139
|
-
|
|
140
|
-
google.accounts.id.prompt();
|
|
141
|
-
}
|
|
139
|
+
google.accounts.id.prompt();
|
|
142
140
|
}
|
|
143
141
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: AuthGoogleService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
144
142
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.5", ngImport: i0, type: AuthGoogleService, providedIn: 'root' });
|
|
@@ -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 { AuthGoogleService, AuthService } from '../public-api';\n\n@Component({\n selector: 'app-auth',\n imports: [CommonModule, ModalButtonComponent, ModalAlertComponent],\n templateUrl: './auth.component.html',\n styleUrls: ['./auth.component.scss'],\n})\nexport class AuthComponent {\n readonly authGoogleService = inject(AuthGoogleService);\n readonly authService = inject(AuthService);\n readonly environmentService = inject(EnvironmentService);\n\n readonly initMember = output<ID>();\n\n constructor() {\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 effect(() => {\n if (this.environmentService.env()) {\n this.authService.loginFromCache();\n this.authGoogleService.initGoogleAuth();\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 <app-modal-button id=\"logout\" icon=\"ri-logout-box-line\" />\n </div>\n <app-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 ></app-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 { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';\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 private readonly platformService = inject(PlatformService);\n\n initGoogleAuth() {\n if (this.platformService.isPlatformBrowser() && google) {\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('google-signin-button')!,\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 if (this.platformService.isPlatformBrowser() && google) {\n google.accounts.id.prompt();\n }\n }\n}\n","import { ApiDto } from \"@ng-vagabond-lab/ng-dsv/api\";\n\nexport const hasRole = (role: string, userRoles?: ApiDto[]) => {\n return userRoles?.find(userRole => userRole['name' as keyof ApiDto] === role) !== undefined;\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;MAqBa,aAAa,CAAA;AACf,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC7C,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,IAAA,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;IAE/C,UAAU,GAAG,MAAM,EAAM;AAElC,IAAA,WAAA,GAAA;QACE,MAAM,CAAC,MAAK;YACV,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;AAC7C,gBAAA,IAAI,CAAC,iBAAiB,CAAC,eAAe,EAAE;YAC1C;iBAAO;AACL,gBAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;YAClE;AACF,QAAA,CAAC,CAAC;QACF,MAAM,CAAC,MAAK;AACV,YAAA,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,EAAE;AACjC,gBAAA,IAAI,CAAC,WAAW,CAAC,cAAc,EAAE;AACjC,gBAAA,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE;YACzC;AACF,QAAA,CAAC,CAAC;IACJ;IAEA,MAAM,GAAA;AACJ,QAAA,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;IAC3B;uGAzB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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;;;MCPY,OAAO,GAAG,CAAC,IAAY,EAAE,SAAoB,KAAI;AAC1D,IAAA,OAAO,SAAS,EAAE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAAC,KAAK,SAAS;AAC/F;;ACJA;;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: 'app-auth',\n imports: [CommonModule, ModalButtonComponent, ModalAlertComponent],\n templateUrl: './auth.component.html',\n styleUrls: ['./auth.component.scss'],\n})\nexport class AuthComponent {\n readonly authGoogleService = inject(AuthGoogleService);\n readonly authService = inject(AuthService);\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.authService.loginFromCache();\n this.authGoogleService.initGoogleAuth();\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 <app-modal-button id=\"logout\" icon=\"ri-logout-box-line\" />\n </div>\n <app-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 ></app-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() {\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('google-signin-button')!,\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 = (role: string, userRoles?: ApiDto[]) => {\n return userRoles?.find(userRole => userRole['name' as keyof ApiDto] === role) !== undefined;\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;;;MAsBa,aAAa,CAAA;AACf,IAAA,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;AAC7C,IAAA,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACjC,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,WAAW,CAAC,cAAc,EAAE;AACjC,gBAAA,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE;gBACvC,IAAI,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;AAC7C,oBAAA,IAAI,CAAC,iBAAiB,CAAC,eAAe,EAAE;gBAC1C;qBAAO;AACL,oBAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;gBAClE;YAC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,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,IAAY,EAAE,SAAoB,KAAI;AAC1D,IAAA,OAAO,SAAS,EAAE,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAsB,CAAC,KAAK,IAAI,CAAC,KAAK,SAAS;AAC/F;;ACJA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { ID, ApiDto, ApiService } from '@ng-vagabond-lab/ng-dsv/api';
|
|
3
3
|
import { EnvironmentService } from '@ng-vagabond-lab/ng-dsv/environment';
|
|
4
|
+
import { PlatformService } from '@ng-vagabond-lab/ng-dsv/platform';
|
|
4
5
|
import { ToastService } from '@ng-vagabond-lab/ng-dsv/ds/toast';
|
|
5
6
|
import { StorageService } from '@ng-vagabond-lab/ng-dsv/storage';
|
|
6
7
|
import { CanActivateFn } from '@angular/router';
|
|
@@ -9,6 +10,7 @@ declare class AuthComponent {
|
|
|
9
10
|
readonly authGoogleService: AuthGoogleService;
|
|
10
11
|
readonly authService: AuthService;
|
|
11
12
|
readonly environmentService: EnvironmentService;
|
|
13
|
+
readonly platformService: PlatformService;
|
|
12
14
|
readonly initMember: i0.OutputEmitterRef<ID>;
|
|
13
15
|
constructor();
|
|
14
16
|
logout(): void;
|
|
@@ -39,7 +41,7 @@ declare const authGuard: CanActivateFn;
|
|
|
39
41
|
declare class AuthGoogleService {
|
|
40
42
|
private readonly authService;
|
|
41
43
|
private readonly environmentService;
|
|
42
|
-
|
|
44
|
+
initGoogle: boolean;
|
|
43
45
|
initGoogleAuth(): void;
|
|
44
46
|
handleCredentialResponse(response: {
|
|
45
47
|
credential: string;
|