@edsis/angular 22.0.38 → 22.0.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.
@@ -1,37 +1,45 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, signal, computed, Injectable, makeEnvironmentProviders, provideEnvironmentInitializer, Component, DestroyRef, Injector, viewChild, effect, afterNextRender, input } from '@angular/core';
2
+ import { InjectionToken, inject, signal, computed, Injectable, makeEnvironmentProviders, provideEnvironmentInitializer, Service, Component, DestroyRef, Injector, viewChild, ElementRef, effect, afterNextRender, input } from '@angular/core';
3
3
  import { DOCUMENT, Location } from '@angular/common';
4
4
  import { HttpErrorResponse, HttpContextToken, HttpClient, HttpContext, provideHttpClient, withFetch, withInterceptors } from '@angular/common/http';
5
- import { Router, RouterOutlet, RouterLink, ActivatedRoute } from '@angular/router';
5
+ import { Router, RouterOutlet, ActivatedRoute, RouterLink } from '@angular/router';
6
6
  import { AuthSessionService, AuthMagicLinkService } from '@edsis/sdk/auth';
7
7
  import { ApiConfiguration, provideApiConfiguration } from '@edsis/sdk/shared';
8
8
  import { firstValueFrom, throwError, from, timeout, startWith, finalize } from 'rxjs';
9
9
  import { switchMap, catchError } from 'rxjs/operators';
10
10
  import { LayoutComponent, LayoutFluidComponent } from '@edsis/theme/layout';
11
- import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';
12
- import * as i1 from '@angular/forms';
13
- import { FormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
11
+ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
12
+ import { AlertComponent, AlertDescriptionComponent } from '@edsis/component/alert';
14
13
  import { AspectRatioComponent } from '@edsis/component/aspect-ratio';
15
14
  import { ButtonComponent } from '@edsis/component/button';
16
- import { CardActionComponent, CardComponent, CardContentComponent, CardDescriptionComponent, CardHeaderComponent, CardTitleComponent, CardFooterComponent } from '@edsis/component/card';
15
+ import { CardActionComponent, CardComponent, CardContentComponent, CardDescriptionComponent, CardFooterComponent, CardHeaderComponent, CardTitleComponent } from '@edsis/component/card';
16
+ import { SpinnerComponent } from '@edsis/component/spinner';
17
+ import * as i1 from '@angular/forms';
18
+ import { FormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
17
19
  import { InputGroupAddonComponent, InputGroupButtonComponent, InputGroupComponent, InputGroupInputComponent } from '@edsis/component/input-group';
18
20
  import { LabelComponent } from '@edsis/component/label';
19
21
  import { SeparatorComponent } from '@edsis/component/separator';
20
- import { AlertComponent, AlertDescriptionComponent } from '@edsis/component/alert';
21
- import { SpinnerComponent } from '@edsis/component/spinner';
22
22
 
23
23
  const DEFAULT_LOGIN_PATH = '/login';
24
24
  const DEFAULT_LOGOUT_PATH = '/logout';
25
25
  const DEFAULT_VERIFY_PATH = '/verify';
26
26
  const DEFAULT_AUTHENTICATED_HOME_PATH = '/dashboard';
27
27
  const DEFAULT_HEALTH_CHECK_TIMEOUT_MS = 4000;
28
+ /**
29
+ * Path route callback Google di dalam `authRoutes`; juga menjadi sumber
30
+ * derivasi `redirectUri` (`${appUrl}/auth/google/callback`), sehingga URL yang
31
+ * didaftarkan di Google Cloud Console selalu konsisten dengan route library.
32
+ */
33
+ const GOOGLE_OAUTH_CALLBACK_ROUTE_PATH = 'auth/google/callback';
28
34
  const EDSIS_AUTH_CONFIG = new InjectionToken('EDSIS_AUTH_CONFIG');
29
35
  function resolveEdsisAuthConfig(config) {
30
36
  const loginPath = normalizePath(config.loginPath, DEFAULT_LOGIN_PATH);
31
37
  const apiUrl = normalizeAbsoluteUrl(config.apiUrl, 'apiUrl');
38
+ const appUrl = normalizeAbsoluteUrl(config.appUrl, 'appUrl');
39
+ const googleClientId = config.oauth?.google?.clientId.trim() ?? '';
32
40
  return {
33
41
  apiUrl,
34
- appUrl: normalizeAbsoluteUrl(config.appUrl, 'appUrl'),
42
+ appUrl,
35
43
  loginPath,
36
44
  logoutPath: normalizePath(config.logoutPath, DEFAULT_LOGOUT_PATH),
37
45
  verifyPath: normalizePath(config.verifyPath, DEFAULT_VERIFY_PATH),
@@ -42,6 +50,14 @@ function resolveEdsisAuthConfig(config) {
42
50
  url: config.healthCheck?.url ?? `${apiUrl.replace(/\/+$/, '')}/health`,
43
51
  timeoutMs: config.healthCheck?.timeoutMs ?? DEFAULT_HEALTH_CHECK_TIMEOUT_MS,
44
52
  },
53
+ oauth: {
54
+ google: googleClientId
55
+ ? {
56
+ clientId: googleClientId,
57
+ redirectUri: `${appUrl}/${GOOGLE_OAUTH_CALLBACK_ROUTE_PATH}`,
58
+ }
59
+ : null,
60
+ },
45
61
  };
46
62
  }
47
63
  function normalizeAbsoluteUrl(value, label) {
@@ -84,6 +100,22 @@ const DEFAULT_EDSIS_AUTH_MESSAGES = {
84
100
  healthRetry: 'Coba lagi',
85
101
  healthChecking: 'Memeriksa ketersediaan layanan…',
86
102
  },
103
+ google: {
104
+ title: 'Menyelesaikan Google Sign-In.',
105
+ intro: 'Kode otorisasi dari Google ditukar menjadi sesi oleh backend, sesi refresh cookie dibentuk, lalu access token disimpan secara lokal untuk aplikasi.',
106
+ badge: 'GOOGLE',
107
+ signInAria: 'Login dengan Google',
108
+ googleRedirecting: 'Mengarahkan ke Google...',
109
+ googleExchangeInProgress: 'Menukar kode otorisasi Google...',
110
+ exchangeInProgressAria: 'Menukar kode otorisasi Google',
111
+ googleStateMismatch: 'Verifikasi keamanan gagal: state OAuth tidak cocok atau hilang. Silakan ulangi login dari awal.',
112
+ googleAccessDenied: 'Login Google dibatalkan. Silakan coba lagi jika ini tidak disengaja.',
113
+ googleCallbackError: 'Login Google gagal diproses.',
114
+ googleRetry: 'Kembali ke login',
115
+ missingAccessToken: 'Login Google berhasil, tetapi access token tidak ditemukan di respons backend.',
116
+ successRedirect: 'Login Google berhasil. Mengarahkan ke dashboard...',
117
+ openDashboard: 'Buka dashboard',
118
+ },
87
119
  logout: {
88
120
  title: 'Mengakhiri sesi Edsis.',
89
121
  intro: 'Halaman ini membersihkan sesi lokal lalu memanggil endpoint logout untuk merevoke refresh-token cookie pada backend.',
@@ -120,6 +152,7 @@ function mergeEdsisAuthMessages(override) {
120
152
  return {
121
153
  brand: { ...DEFAULT_EDSIS_AUTH_MESSAGES.brand, ...override.brand },
122
154
  login: { ...DEFAULT_EDSIS_AUTH_MESSAGES.login, ...override.login },
155
+ google: { ...DEFAULT_EDSIS_AUTH_MESSAGES.google, ...override.google },
123
156
  logout: { ...DEFAULT_EDSIS_AUTH_MESSAGES.logout, ...override.logout },
124
157
  verify: { ...DEFAULT_EDSIS_AUTH_MESSAGES.verify, ...override.verify },
125
158
  };
@@ -765,6 +798,61 @@ const guestOnlyGuard = async () => {
765
798
  return router.parseUrl(authConfig.authenticatedHomePath);
766
799
  };
767
800
 
801
+ /**
802
+ * Menukar authorization code Google menjadi sesi lewat backend
803
+ * (`POST {apiUrl}/auth/google`): client secret hanya ada di server, backend
804
+ * men-set refresh cookie (karena itu `withCredentials`), dan respons berformat
805
+ * sama dengan verify magic-link sehingga bisa langsung ke `persistSession`.
806
+ */
807
+ class AuthGoogleOauthService {
808
+ http = inject(HttpClient);
809
+ config = inject(EDSIS_AUTH_CONFIG);
810
+ exchangeAuthorizationCode(code) {
811
+ const googleOauth = this.config.oauth.google;
812
+ if (!googleOauth) {
813
+ return throwError(() => new Error('Edsis auth: Google OAuth is not configured.'));
814
+ }
815
+ return this.http.post(`${this.config.apiUrl}/auth/google`, { code, redirectUri: googleOauth.redirectUri }, { withCredentials: true });
816
+ }
817
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleOauthService, deps: [], target: i0.ɵɵFactoryTarget.Service });
818
+ static ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleOauthService });
819
+ }
820
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleOauthService, decorators: [{
821
+ type: Service
822
+ }] });
823
+
824
+ const GOOGLE_OAUTH_STATE_STORAGE_KEY = 'auth-google-state';
825
+ const GOOGLE_OAUTH_AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/v2/auth';
826
+ const GOOGLE_OAUTH_SCOPE = 'openid email profile';
827
+ const GOOGLE_OAUTH_STATE_BYTE_LENGTH = 16;
828
+ /** Nilai `state` acak berbasis crypto (anti-CSRF untuk round-trip OAuth). */
829
+ function createGoogleOauthState(windowRef) {
830
+ const randomBytes = windowRef.crypto.getRandomValues(new Uint8Array(GOOGLE_OAUTH_STATE_BYTE_LENGTH));
831
+ return Array.from(randomBytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
832
+ }
833
+ function buildGoogleAuthorizeUrl(options) {
834
+ const authorizeUrl = new URL(GOOGLE_OAUTH_AUTHORIZE_URL);
835
+ authorizeUrl.searchParams.set('client_id', options.clientId);
836
+ authorizeUrl.searchParams.set('redirect_uri', options.redirectUri);
837
+ authorizeUrl.searchParams.set('response_type', 'code');
838
+ authorizeUrl.searchParams.set('scope', GOOGLE_OAUTH_SCOPE);
839
+ authorizeUrl.searchParams.set('state', options.state);
840
+ return authorizeUrl.toString();
841
+ }
842
+ function storeGoogleOauthState(documentRef, state) {
843
+ documentRef.defaultView?.sessionStorage?.setItem(GOOGLE_OAUTH_STATE_STORAGE_KEY, state);
844
+ }
845
+ /**
846
+ * Baca lalu hapus state dari sessionStorage. State sekali pakai: dikonsumsi di
847
+ * semua cabang callback agar tidak bocor ke percobaan login berikutnya.
848
+ */
849
+ function consumeGoogleOauthState(documentRef) {
850
+ const sessionStorageRef = documentRef.defaultView?.sessionStorage;
851
+ const state = sessionStorageRef?.getItem(GOOGLE_OAUTH_STATE_STORAGE_KEY)?.trim() ?? '';
852
+ sessionStorageRef?.removeItem(GOOGLE_OAUTH_STATE_STORAGE_KEY);
853
+ return state;
854
+ }
855
+
768
856
  class AuthShellPage {
769
857
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthShellPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
770
858
  static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.0.5", type: AuthShellPage, isStandalone: true, selector: "edsis-auth-shell-page", host: { classAttribute: "contents" }, ngImport: i0, template: `
@@ -831,6 +919,24 @@ function getResponseMessage(response, fallback) {
831
919
  }
832
920
  return normalizeText(response.message) ?? fallback;
833
921
  }
922
+ /**
923
+ * Pesan error dari body respons backend saja. Berbeda dengan `getErrorMessage`,
924
+ * `HttpErrorResponse.message` sintetis ("Http failure response for ...") tidak
925
+ * pernah dipakai, sehingga tanpa pesan backend selalu jatuh ke fallback ramah.
926
+ */
927
+ function getBackendErrorMessage(error, fallback) {
928
+ if (!(error instanceof HttpErrorResponse)) {
929
+ return fallback;
930
+ }
931
+ const errorBody = error.error;
932
+ if (typeof errorBody === 'string') {
933
+ return normalizeText(errorBody) ?? fallback;
934
+ }
935
+ if (hasMessage(errorBody)) {
936
+ return normalizeText(errorBody.message) ?? fallback;
937
+ }
938
+ return fallback;
939
+ }
834
940
  function getErrorMessage(error, fallback) {
835
941
  if (error instanceof HttpErrorResponse) {
836
942
  const errorBody = error.error;
@@ -858,7 +964,247 @@ function normalizeText(value) {
858
964
  return normalizedValue.length > 0 ? normalizedValue : null;
859
965
  }
860
966
 
967
+ class AuthGoogleCallbackPage {
968
+ documentRef = inject(DOCUMENT);
969
+ destroyRef = inject(DestroyRef);
970
+ injector = inject(Injector);
971
+ route = inject(ActivatedRoute);
972
+ router = inject(Router);
973
+ location = inject(Location);
974
+ authGoogleOauthService = inject(AuthGoogleOauthService);
975
+ authConfig = inject(EDSIS_AUTH_CONFIG);
976
+ messages = inject(EDSIS_AUTH_MESSAGES);
977
+ loginPath = this.authConfig.loginPath;
978
+ authenticatedHomePath = this.authConfig.authenticatedHomePath;
979
+ state = signal('pending', /* @ts-ignore */
980
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
981
+ message = signal(this.messages.google.googleExchangeInProgress, /* @ts-ignore */
982
+ ...(ngDevMode ? [{ debugName: "message" }] : /* istanbul ignore next */ []));
983
+ // `a[Button]` adalah komponen, jadi tanpa `read` query template-ref ini
984
+ // mengembalikan instance ButtonComponent — bukan elemen anchor-nya.
985
+ retryLink = viewChild('retryLink', { ...(ngDevMode ? { debugName: "retryLink" } : /* istanbul ignore next */ {}), read: ElementRef });
986
+ constructor() {
987
+ effect(() => {
988
+ if (this.state() !== 'error') {
989
+ return;
990
+ }
991
+ afterNextRender(() => this.retryLink()?.nativeElement.focus(), { injector: this.injector });
992
+ });
993
+ this.handleCallback();
994
+ }
995
+ handleCallback() {
996
+ const queryParams = this.route.snapshot.queryParamMap;
997
+ const oauthError = queryParams.get('error')?.trim() ?? '';
998
+ const code = queryParams.get('code')?.trim() ?? '';
999
+ const returnedState = queryParams.get('state')?.trim() ?? '';
1000
+ // State dikonsumsi (dibaca + dihapus) sebelum bercabang supaya bersih di
1001
+ // semua cabang, termasuk cabang error dari Google.
1002
+ const storedState = consumeGoogleOauthState(this.documentRef);
1003
+ this.clearCallbackParamsFromAddressBar();
1004
+ if (oauthError) {
1005
+ this.fail(oauthError === 'access_denied'
1006
+ ? this.messages.google.googleAccessDenied
1007
+ : this.messages.google.googleCallbackError);
1008
+ return;
1009
+ }
1010
+ if (!returnedState || !storedState || returnedState !== storedState) {
1011
+ this.fail(this.messages.google.googleStateMismatch);
1012
+ return;
1013
+ }
1014
+ if (!code) {
1015
+ this.fail(this.messages.google.googleCallbackError);
1016
+ return;
1017
+ }
1018
+ this.exchange(code);
1019
+ }
1020
+ clearCallbackParamsFromAddressBar() {
1021
+ this.location.replaceState(`/${GOOGLE_OAUTH_CALLBACK_ROUTE_PATH}`);
1022
+ }
1023
+ exchange(code) {
1024
+ this.state.set('pending');
1025
+ this.message.set(this.messages.google.googleExchangeInProgress);
1026
+ this.authGoogleOauthService
1027
+ .exchangeAuthorizationCode(code)
1028
+ .pipe(takeUntilDestroyed(this.destroyRef))
1029
+ .subscribe({
1030
+ next: (response) => {
1031
+ const session = persistSession(this.documentRef, response.data);
1032
+ if (!session) {
1033
+ this.fail(this.messages.google.missingAccessToken);
1034
+ return;
1035
+ }
1036
+ this.state.set('success');
1037
+ this.message.set(getResponseMessage(response, this.messages.google.successRedirect));
1038
+ void this.router.navigateByUrl(this.authenticatedHomePath, { replaceUrl: true });
1039
+ },
1040
+ error: (error) => {
1041
+ this.fail(getBackendErrorMessage(error, this.messages.google.googleCallbackError));
1042
+ },
1043
+ });
1044
+ }
1045
+ fail(message) {
1046
+ this.state.set('error');
1047
+ this.message.set(message);
1048
+ }
1049
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleCallbackPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
1050
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: AuthGoogleCallbackPage, isStandalone: true, selector: "AuthGoogleCallbackPage", host: { classAttribute: "block" }, viewQueries: [{ propertyName: "retryLink", first: true, predicate: ["retryLink"], descendants: true, read: ElementRef, isSignal: true }], ngImport: i0, template: `
1051
+ <Card
1052
+ class="w-full overflow-hidden rounded-none border-border/80 bg-card/95 shadow-2xl backdrop-blur-sm"
1053
+ >
1054
+ <CardHeader
1055
+ class="grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-x-4 gap-y-3 border-b border-border/60 bg-muted/15 pb-4 sm:pb-5"
1056
+ >
1057
+ <div class="w-16 shrink-0 sm:w-20">
1058
+ <AspectRatio [ratio]="3 / 2" class="overflow-hidden rounded-none bg-primary">
1059
+ <div
1060
+ class="flex h-full w-full items-center justify-center px-1 text-[1.25rem] leading-none tracking-[-0.08em] text-primary-foreground sm:text-[1.55rem]"
1061
+ style="font-family: 'Arial Black', Arial, sans-serif;"
1062
+ >
1063
+ {{ messages.brand.mark }}
1064
+ </div>
1065
+ </AspectRatio>
1066
+ </div>
1067
+ <div class="min-w-0 space-y-0.5 pt-0.5 sm:pt-1">
1068
+ <CardTitle class="text-xl leading-tight sm:text-2xl">{{
1069
+ messages.google.title
1070
+ }}</CardTitle>
1071
+ <p CardDescription class="max-w-xl leading-6">
1072
+ {{ messages.google.intro }}
1073
+ </p>
1074
+ </div>
1075
+ <CardAction
1076
+ class="col-start-3 row-span-1 mt-0! pt-0.5 text-xs font-medium uppercase tracking-[0.24em] text-muted-foreground sm:pt-1 sm:text-sm"
1077
+ >
1078
+ {{ messages.google.badge }}
1079
+ </CardAction>
1080
+ </CardHeader>
1081
+
1082
+ <CardContent class="space-y-4 pt-6 sm:pt-7">
1083
+ <Alert
1084
+ [variant]="state() === 'error' ? 'destructive' : 'default'"
1085
+ class="bg-background/70 shadow-sm"
1086
+ >
1087
+ @if (state() === 'pending') {
1088
+ <Spinner class="mt-0.5 size-4" [aria-label]="messages.google.exchangeInProgressAria" />
1089
+ }
1090
+
1091
+ <AlertDescription>
1092
+ {{ message() }}
1093
+ </AlertDescription>
1094
+ </Alert>
1095
+ </CardContent>
1096
+
1097
+ @if (state() !== 'pending') {
1098
+ <CardFooter class="flex flex-wrap gap-3 border-t border-border/60 bg-muted/10 pt-4 sm:pt-5">
1099
+ @if (state() === 'error') {
1100
+ <a #retryLink Button [routerLink]="loginPath" variant="default">
1101
+ {{ messages.google.googleRetry }}
1102
+ </a>
1103
+ }
1104
+ <a
1105
+ Button
1106
+ [routerLink]="authenticatedHomePath"
1107
+ [variant]="state() === 'error' ? 'outline' : 'default'"
1108
+ >
1109
+ {{ messages.google.openDashboard }}
1110
+ </a>
1111
+ </CardFooter>
1112
+ }
1113
+ </Card>
1114
+ `, isInline: true, dependencies: [{ kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "browserUrl", "routerLink"] }, { kind: "component", type: AlertComponent, selector: "Alert", inputs: ["variant", "class"] }, { kind: "component", type: AlertDescriptionComponent, selector: "AlertDescription", inputs: ["class"] }, { kind: "component", type: AspectRatioComponent, selector: "AspectRatio", inputs: ["ratio", "class"] }, { kind: "component", type: ButtonComponent, selector: "button[Button], a[Button]", inputs: ["variant", "size", "class"] }, { kind: "component", type: CardActionComponent, selector: "CardAction", inputs: ["class"] }, { kind: "component", type: CardComponent, selector: "Card", inputs: ["size", "class"] }, { kind: "component", type: CardContentComponent, selector: "CardContent", inputs: ["class"] }, { kind: "component", type: CardDescriptionComponent, selector: "CardDescription, p[CardDescription]", inputs: ["class"] }, { kind: "component", type: CardFooterComponent, selector: "CardFooter", inputs: ["class"] }, { kind: "component", type: CardHeaderComponent, selector: "CardHeader", inputs: ["class"] }, { kind: "component", type: CardTitleComponent, selector: "CardTitle, h3[CardTitle]", inputs: ["class"] }, { kind: "component", type: SpinnerComponent, selector: "Spinner", inputs: ["class", "decorative", "aria-label", "aria-labelledby"] }] });
1115
+ }
1116
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleCallbackPage, decorators: [{
1117
+ type: Component,
1118
+ args: [{
1119
+ selector: 'AuthGoogleCallbackPage',
1120
+ imports: [
1121
+ RouterLink,
1122
+ AlertComponent,
1123
+ AlertDescriptionComponent,
1124
+ AspectRatioComponent,
1125
+ ButtonComponent,
1126
+ CardActionComponent,
1127
+ CardComponent,
1128
+ CardContentComponent,
1129
+ CardDescriptionComponent,
1130
+ CardFooterComponent,
1131
+ CardHeaderComponent,
1132
+ CardTitleComponent,
1133
+ SpinnerComponent,
1134
+ ],
1135
+ host: {
1136
+ class: 'block',
1137
+ },
1138
+ template: `
1139
+ <Card
1140
+ class="w-full overflow-hidden rounded-none border-border/80 bg-card/95 shadow-2xl backdrop-blur-sm"
1141
+ >
1142
+ <CardHeader
1143
+ class="grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-x-4 gap-y-3 border-b border-border/60 bg-muted/15 pb-4 sm:pb-5"
1144
+ >
1145
+ <div class="w-16 shrink-0 sm:w-20">
1146
+ <AspectRatio [ratio]="3 / 2" class="overflow-hidden rounded-none bg-primary">
1147
+ <div
1148
+ class="flex h-full w-full items-center justify-center px-1 text-[1.25rem] leading-none tracking-[-0.08em] text-primary-foreground sm:text-[1.55rem]"
1149
+ style="font-family: 'Arial Black', Arial, sans-serif;"
1150
+ >
1151
+ {{ messages.brand.mark }}
1152
+ </div>
1153
+ </AspectRatio>
1154
+ </div>
1155
+ <div class="min-w-0 space-y-0.5 pt-0.5 sm:pt-1">
1156
+ <CardTitle class="text-xl leading-tight sm:text-2xl">{{
1157
+ messages.google.title
1158
+ }}</CardTitle>
1159
+ <p CardDescription class="max-w-xl leading-6">
1160
+ {{ messages.google.intro }}
1161
+ </p>
1162
+ </div>
1163
+ <CardAction
1164
+ class="col-start-3 row-span-1 mt-0! pt-0.5 text-xs font-medium uppercase tracking-[0.24em] text-muted-foreground sm:pt-1 sm:text-sm"
1165
+ >
1166
+ {{ messages.google.badge }}
1167
+ </CardAction>
1168
+ </CardHeader>
1169
+
1170
+ <CardContent class="space-y-4 pt-6 sm:pt-7">
1171
+ <Alert
1172
+ [variant]="state() === 'error' ? 'destructive' : 'default'"
1173
+ class="bg-background/70 shadow-sm"
1174
+ >
1175
+ @if (state() === 'pending') {
1176
+ <Spinner class="mt-0.5 size-4" [aria-label]="messages.google.exchangeInProgressAria" />
1177
+ }
1178
+
1179
+ <AlertDescription>
1180
+ {{ message() }}
1181
+ </AlertDescription>
1182
+ </Alert>
1183
+ </CardContent>
1184
+
1185
+ @if (state() !== 'pending') {
1186
+ <CardFooter class="flex flex-wrap gap-3 border-t border-border/60 bg-muted/10 pt-4 sm:pt-5">
1187
+ @if (state() === 'error') {
1188
+ <a #retryLink Button [routerLink]="loginPath" variant="default">
1189
+ {{ messages.google.googleRetry }}
1190
+ </a>
1191
+ }
1192
+ <a
1193
+ Button
1194
+ [routerLink]="authenticatedHomePath"
1195
+ [variant]="state() === 'error' ? 'outline' : 'default'"
1196
+ >
1197
+ {{ messages.google.openDashboard }}
1198
+ </a>
1199
+ </CardFooter>
1200
+ }
1201
+ </Card>
1202
+ `,
1203
+ }]
1204
+ }], ctorParameters: () => [], propDecorators: { retryLink: [{ type: i0.ViewChild, args: ['retryLink', { ...{ read: ElementRef }, isSignal: true }] }] } });
1205
+
861
1206
  class AuthLoginPage {
1207
+ documentRef = inject(DOCUMENT);
862
1208
  destroyRef = inject(DestroyRef);
863
1209
  formBuilder = inject(FormBuilder);
864
1210
  injector = inject(Injector);
@@ -866,6 +1212,9 @@ class AuthLoginPage {
866
1212
  authConfig = inject(EDSIS_AUTH_CONFIG);
867
1213
  messages = inject(EDSIS_AUTH_MESSAGES);
868
1214
  health = inject(AuthHealthService);
1215
+ googleOauth = this.authConfig.oauth.google;
1216
+ isGoogleRedirecting = signal(false, /* @ts-ignore */
1217
+ ...(ngDevMode ? [{ debugName: "isGoogleRedirecting" }] : /* istanbul ignore next */ []));
869
1218
  form = this.formBuilder.nonNullable.group({
870
1219
  email: ['', [Validators.required, Validators.email, Validators.maxLength(255)]],
871
1220
  });
@@ -878,8 +1227,9 @@ class AuthLoginPage {
878
1227
  emailControl = this.form.controls.email;
879
1228
  emailFeedbackId = 'email-feedback';
880
1229
  healthBannerId = 'auth-health-banner';
881
- retryButton = viewChild('healthRetryButton', /* @ts-ignore */
882
- ...(ngDevMode ? [{ debugName: "retryButton" }] : /* istanbul ignore next */ []));
1230
+ // `button[Button]` adalah komponen, jadi tanpa `read` query template-ref ini
1231
+ // mengembalikan instance ButtonComponent — bukan elemen button-nya.
1232
+ retryButton = viewChild('healthRetryButton', { ...(ngDevMode ? { debugName: "retryButton" } : /* istanbul ignore next */ {}), read: ElementRef });
883
1233
  emailControlState = toSignal(this.emailControl.events.pipe(startWith(null)), {
884
1234
  initialValue: null,
885
1235
  });
@@ -948,6 +1298,26 @@ class AuthLoginPage {
948
1298
  retryHealth() {
949
1299
  void this.health.check();
950
1300
  }
1301
+ signInWithGoogle() {
1302
+ const googleOauth = this.googleOauth;
1303
+ const windowRef = this.documentRef.defaultView;
1304
+ if (!googleOauth || !windowRef || this.isGoogleRedirecting()) {
1305
+ return;
1306
+ }
1307
+ this.isGoogleRedirecting.set(true);
1308
+ const state = createGoogleOauthState(windowRef);
1309
+ storeGoogleOauthState(this.documentRef, state);
1310
+ this.redirectTo(buildGoogleAuthorizeUrl({
1311
+ clientId: googleOauth.clientId,
1312
+ redirectUri: googleOauth.redirectUri,
1313
+ state,
1314
+ }));
1315
+ }
1316
+ // Full-page redirect keluar dari SPA (bukan Router). Method terpisah karena
1317
+ // jsdom tidak mengizinkan stub pada location.assign.
1318
+ redirectTo(url) {
1319
+ this.documentRef.defaultView?.location.assign(url);
1320
+ }
951
1321
  async submit() {
952
1322
  if (this.form.invalid) {
953
1323
  this.form.markAllAsTouched();
@@ -980,7 +1350,7 @@ class AuthLoginPage {
980
1350
  });
981
1351
  }
982
1352
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthLoginPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
983
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: AuthLoginPage, isStandalone: true, selector: "edsis-auth-login-page", host: { classAttribute: "block" }, viewQueries: [{ propertyName: "retryButton", first: true, predicate: ["healthRetryButton"], descendants: true, isSignal: true }], ngImport: i0, template: `
1353
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.5", type: AuthLoginPage, isStandalone: true, selector: "edsis-auth-login-page", host: { classAttribute: "block" }, viewQueries: [{ propertyName: "retryButton", first: true, predicate: ["healthRetryButton"], descendants: true, read: ElementRef, isSignal: true }], ngImport: i0, template: `
984
1354
  <Card
985
1355
  class="w-full overflow-hidden rounded-none border-border/80 bg-card/95 shadow-2xl backdrop-blur-sm"
986
1356
  >
@@ -1116,9 +1486,10 @@ class AuthLoginPage {
1116
1486
  type="button"
1117
1487
  variant="outline"
1118
1488
  size="lg"
1119
- disabled
1120
- [attr.aria-label]="messages.login.oauthGoogleAria"
1121
- [attr.title]="messages.login.oauthComingSoon"
1489
+ [disabled]="!googleOauth || isGoogleRedirecting()"
1490
+ [attr.aria-label]="googleOauth ? messages.google.signInAria : messages.login.oauthGoogleAria"
1491
+ [attr.title]="googleOauth ? null : messages.login.oauthComingSoon"
1492
+ (click)="signInWithGoogle()"
1122
1493
  class="h-12 gap-3 text-[0.74rem] font-medium uppercase tracking-[0.16em]"
1123
1494
  >
1124
1495
  <span
@@ -1144,7 +1515,7 @@ class AuthLoginPage {
1144
1515
  />
1145
1516
  </svg>
1146
1517
  </span>
1147
- Google
1518
+ {{ isGoogleRedirecting() ? messages.google.googleRedirecting : 'Google' }}
1148
1519
  </button>
1149
1520
  <button
1150
1521
  Button
@@ -1196,6 +1567,12 @@ class AuthLoginPage {
1196
1567
  Apple
1197
1568
  </button>
1198
1569
  </div>
1570
+
1571
+ @if (isGoogleRedirecting()) {
1572
+ <p class="sr-only" role="status" aria-live="polite">
1573
+ {{ messages.google.googleRedirecting }}
1574
+ </p>
1575
+ }
1199
1576
  </form>
1200
1577
  </CardContent>
1201
1578
  </Card>
@@ -1361,9 +1738,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1361
1738
  type="button"
1362
1739
  variant="outline"
1363
1740
  size="lg"
1364
- disabled
1365
- [attr.aria-label]="messages.login.oauthGoogleAria"
1366
- [attr.title]="messages.login.oauthComingSoon"
1741
+ [disabled]="!googleOauth || isGoogleRedirecting()"
1742
+ [attr.aria-label]="googleOauth ? messages.google.signInAria : messages.login.oauthGoogleAria"
1743
+ [attr.title]="googleOauth ? null : messages.login.oauthComingSoon"
1744
+ (click)="signInWithGoogle()"
1367
1745
  class="h-12 gap-3 text-[0.74rem] font-medium uppercase tracking-[0.16em]"
1368
1746
  >
1369
1747
  <span
@@ -1389,7 +1767,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1389
1767
  />
1390
1768
  </svg>
1391
1769
  </span>
1392
- Google
1770
+ {{ isGoogleRedirecting() ? messages.google.googleRedirecting : 'Google' }}
1393
1771
  </button>
1394
1772
  <button
1395
1773
  Button
@@ -1441,12 +1819,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1441
1819
  Apple
1442
1820
  </button>
1443
1821
  </div>
1822
+
1823
+ @if (isGoogleRedirecting()) {
1824
+ <p class="sr-only" role="status" aria-live="polite">
1825
+ {{ messages.google.googleRedirecting }}
1826
+ </p>
1827
+ }
1444
1828
  </form>
1445
1829
  </CardContent>
1446
1830
  </Card>
1447
1831
  `,
1448
1832
  }]
1449
- }], ctorParameters: () => [], propDecorators: { retryButton: [{ type: i0.ViewChild, args: ['healthRetryButton', { isSignal: true }] }] } });
1833
+ }], ctorParameters: () => [], propDecorators: { retryButton: [{ type: i0.ViewChild, args: ['healthRetryButton', { ...{ read: ElementRef }, isSignal: true }] }] } });
1450
1834
 
1451
1835
  class AuthLogoutPage {
1452
1836
  destroyRef = inject(DestroyRef);
@@ -1888,6 +2272,12 @@ const authRoutes = [
1888
2272
  canActivate: [guestOnlyGuard],
1889
2273
  component: AuthLoginPage,
1890
2274
  },
2275
+ {
2276
+ path: GOOGLE_OAUTH_CALLBACK_ROUTE_PATH,
2277
+ title: 'Google Sign-In',
2278
+ canActivate: [guestOnlyGuard],
2279
+ component: AuthGoogleCallbackPage,
2280
+ },
1891
2281
  {
1892
2282
  path: 'logout',
1893
2283
  title: 'Logout',
@@ -1907,5 +2297,5 @@ const authRoutes = [
1907
2297
  * Generated bundle index. Do not edit.
1908
2298
  */
1909
2299
 
1910
- export { AUTH_SESSION_CHANGE_EVENT, AuthLoginPage, AuthLogoutPage, AuthShellPage, AuthVerifyPage, DEFAULT_EDSIS_AUTH_MESSAGES, EDSIS_AUTH_CONFIG, EDSIS_AUTH_MESSAGES, EDSIS_SKIP_AUTH, EDSIS_SKIP_SESSION_REFRESH, authRoutes, authenticatedGuard, clearStoredSession, edsisAuthInterceptor, guestOnlyGuard, hasStoredSession, homeRedirectGuard, injectSessionClear, injectSessionRefresh, injectSessionState, mergeEdsisAuthMessages, persistSession, provideEdsisAuth, readStoredAccessToken, readStoredSession, resolveEdsisAuthConfig, shouldClearSessionAfterRefreshFailure, startAuthSessionMonitor, validateStoredSession, ɵresetAuthSessionModuleState };
2300
+ export { AUTH_SESSION_CHANGE_EVENT, AuthGoogleCallbackPage, AuthGoogleOauthService, AuthLoginPage, AuthLogoutPage, AuthShellPage, AuthVerifyPage, DEFAULT_EDSIS_AUTH_MESSAGES, EDSIS_AUTH_CONFIG, EDSIS_AUTH_MESSAGES, EDSIS_SKIP_AUTH, EDSIS_SKIP_SESSION_REFRESH, GOOGLE_OAUTH_AUTHORIZE_URL, GOOGLE_OAUTH_CALLBACK_ROUTE_PATH, GOOGLE_OAUTH_STATE_STORAGE_KEY, authRoutes, authenticatedGuard, buildGoogleAuthorizeUrl, clearStoredSession, consumeGoogleOauthState, createGoogleOauthState, edsisAuthInterceptor, guestOnlyGuard, hasStoredSession, homeRedirectGuard, injectSessionClear, injectSessionRefresh, injectSessionState, mergeEdsisAuthMessages, persistSession, provideEdsisAuth, readStoredAccessToken, readStoredSession, resolveEdsisAuthConfig, shouldClearSessionAfterRefreshFailure, startAuthSessionMonitor, storeGoogleOauthState, validateStoredSession, ɵresetAuthSessionModuleState };
1911
2301
  //# sourceMappingURL=edsis-angular-module-auth.mjs.map