@edsis/angular 22.0.39 → 22.0.41

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.
package/README.md CHANGED
@@ -9,6 +9,65 @@ Published entry points:
9
9
 
10
10
  The generated API SDK is published separately as `@edsis/sdk`.
11
11
 
12
+ ## `module/auth`: Google Sign-In
13
+
14
+ `@edsis/angular/module/auth` ships an optional Google Sign-In using the OAuth
15
+ authorization-code flow. It stays disabled (the login button remains a
16
+ "coming soon" placeholder) until a client ID is configured:
17
+
18
+ ```ts
19
+ provideEdsisAuth({
20
+ apiUrl: environment.apiUrl,
21
+ appUrl: environment.appUrl,
22
+ oauth: {
23
+ google: { clientId: environment.google.clientId },
24
+ },
25
+ });
26
+ ```
27
+
28
+ - `redirectUri` is **not** configurable; the library derives it from `appUrl`
29
+ as `${appUrl}/auth/google/callback` and `authRoutes` serves that path with
30
+ `AuthGoogleCallbackPage`. Register exactly this URI in the Google Cloud
31
+ Console.
32
+ - An empty `clientId` is treated as "not configured", so a build-time injected
33
+ environment value can be passed through as-is.
34
+ - Clicking the Google button stores a crypto-random `state` in sessionStorage
35
+ (`auth-google-state`) and performs a full-page redirect to
36
+ `https://accounts.google.com/o/oauth2/v2/auth` with
37
+ `client_id`, `redirect_uri`, `response_type=code`,
38
+ `scope=openid email profile`, and `state`.
39
+ - Microsoft and Apple remain placeholders.
40
+
41
+ ### Backend contract
42
+
43
+ The code exchange happens on the backend so the client secret never reaches
44
+ the frontend. The callback page calls the generated SDK method
45
+ `AuthSessionService.exchangeGoogleCode(...)` from `@edsis/sdk/auth` (no raw
46
+ `HttpClient`, consistent with `verifyMagicLink`/`refreshAuthToken`), which maps
47
+ to:
48
+
49
+ ```http
50
+ POST {apiUrl}/v1/auth/google
51
+ Body: { "code": string, "redirectUri": string }
52
+ ```
53
+
54
+ Because the path lives under `/v1/auth/`, `edsisAuthInterceptor` sends it with
55
+ cookie credentials automatically. The endpoint:
56
+
57
+ 1. exchanges `code` at Google's token endpoint using the server-side client
58
+ secret and the received `redirectUri`;
59
+ 2. sets the refresh-token cookie, exactly like magic-link verify does;
60
+ 3. responds with a session payload **identical** to `POST /v1/auth/verify`
61
+ (`{ status, message, data: { access_token, user_id, role, name } }`).
62
+
63
+ On success the callback page runs `persistSession` and redirects to
64
+ `authenticatedHomePath`; on failure it shows the backend `message` when one is
65
+ provided (with a retry link back to `loginPath`).
66
+
67
+ The endpoint definition comes from `openapi.bundle.yaml`; regenerate the SDK in
68
+ `library/sdk` after spec changes with `bun run gen:sdk` (driven by
69
+ `config/sdk.config.json`, generator: `@ojiepermana/angular-sdk`).
70
+
12
71
  ## Generate and build
13
72
 
14
73
  Use the root workspace scripts so SDK generation and library packaging stay in sync:
@@ -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, 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,38 @@ const guestOnlyGuard = async () => {
765
798
  return router.parseUrl(authConfig.authenticatedHomePath);
766
799
  };
767
800
 
801
+ const GOOGLE_OAUTH_STATE_STORAGE_KEY = 'auth-google-state';
802
+ const GOOGLE_OAUTH_AUTHORIZE_URL = 'https://accounts.google.com/o/oauth2/v2/auth';
803
+ const GOOGLE_OAUTH_SCOPE = 'openid email profile';
804
+ const GOOGLE_OAUTH_STATE_BYTE_LENGTH = 16;
805
+ /** Nilai `state` acak berbasis crypto (anti-CSRF untuk round-trip OAuth). */
806
+ function createGoogleOauthState(windowRef) {
807
+ const randomBytes = windowRef.crypto.getRandomValues(new Uint8Array(GOOGLE_OAUTH_STATE_BYTE_LENGTH));
808
+ return Array.from(randomBytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
809
+ }
810
+ function buildGoogleAuthorizeUrl(options) {
811
+ const authorizeUrl = new URL(GOOGLE_OAUTH_AUTHORIZE_URL);
812
+ authorizeUrl.searchParams.set('client_id', options.clientId);
813
+ authorizeUrl.searchParams.set('redirect_uri', options.redirectUri);
814
+ authorizeUrl.searchParams.set('response_type', 'code');
815
+ authorizeUrl.searchParams.set('scope', GOOGLE_OAUTH_SCOPE);
816
+ authorizeUrl.searchParams.set('state', options.state);
817
+ return authorizeUrl.toString();
818
+ }
819
+ function storeGoogleOauthState(documentRef, state) {
820
+ documentRef.defaultView?.sessionStorage?.setItem(GOOGLE_OAUTH_STATE_STORAGE_KEY, state);
821
+ }
822
+ /**
823
+ * Baca lalu hapus state dari sessionStorage. State sekali pakai: dikonsumsi di
824
+ * semua cabang callback agar tidak bocor ke percobaan login berikutnya.
825
+ */
826
+ function consumeGoogleOauthState(documentRef) {
827
+ const sessionStorageRef = documentRef.defaultView?.sessionStorage;
828
+ const state = sessionStorageRef?.getItem(GOOGLE_OAUTH_STATE_STORAGE_KEY)?.trim() ?? '';
829
+ sessionStorageRef?.removeItem(GOOGLE_OAUTH_STATE_STORAGE_KEY);
830
+ return state;
831
+ }
832
+
768
833
  class AuthShellPage {
769
834
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthShellPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
770
835
  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: `
@@ -797,16 +862,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
797
862
  }]
798
863
  }] });
799
864
 
800
- function buildVerifyUrl(config, runtimeOrigin = readRuntimeOrigin()) {
801
- const baseUrl = normalizeText(runtimeOrigin) ?? config.appUrl;
802
- return new URL(config.verifyPath, `${baseUrl}/`).toString();
803
- }
804
- function readRuntimeOrigin() {
805
- if (typeof window === 'undefined') {
806
- return null;
807
- }
808
- return normalizeText(window.location.origin);
809
- }
810
865
  function extractMagicToken(queryToken, fragment) {
811
866
  const tokenFromQuery = normalizeText(queryToken);
812
867
  if (tokenFromQuery) {
@@ -831,6 +886,24 @@ function getResponseMessage(response, fallback) {
831
886
  }
832
887
  return normalizeText(response.message) ?? fallback;
833
888
  }
889
+ /**
890
+ * Pesan error dari body respons backend saja. Berbeda dengan `getErrorMessage`,
891
+ * `HttpErrorResponse.message` sintetis ("Http failure response for ...") tidak
892
+ * pernah dipakai, sehingga tanpa pesan backend selalu jatuh ke fallback ramah.
893
+ */
894
+ function getBackendErrorMessage(error, fallback) {
895
+ if (!(error instanceof HttpErrorResponse)) {
896
+ return fallback;
897
+ }
898
+ const errorBody = error.error;
899
+ if (typeof errorBody === 'string') {
900
+ return normalizeText(errorBody) ?? fallback;
901
+ }
902
+ if (hasMessage(errorBody)) {
903
+ return normalizeText(errorBody.message) ?? fallback;
904
+ }
905
+ return fallback;
906
+ }
834
907
  function getErrorMessage(error, fallback) {
835
908
  if (error instanceof HttpErrorResponse) {
836
909
  const errorBody = error.error;
@@ -858,7 +931,257 @@ function normalizeText(value) {
858
931
  return normalizedValue.length > 0 ? normalizedValue : null;
859
932
  }
860
933
 
934
+ class AuthGoogleCallbackPage {
935
+ documentRef = inject(DOCUMENT);
936
+ destroyRef = inject(DestroyRef);
937
+ injector = inject(Injector);
938
+ route = inject(ActivatedRoute);
939
+ router = inject(Router);
940
+ location = inject(Location);
941
+ authSessionService = inject(AuthSessionService);
942
+ authConfig = inject(EDSIS_AUTH_CONFIG);
943
+ messages = inject(EDSIS_AUTH_MESSAGES);
944
+ loginPath = this.authConfig.loginPath;
945
+ authenticatedHomePath = this.authConfig.authenticatedHomePath;
946
+ state = signal('pending', /* @ts-ignore */
947
+ ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
948
+ message = signal(this.messages.google.googleExchangeInProgress, /* @ts-ignore */
949
+ ...(ngDevMode ? [{ debugName: "message" }] : /* istanbul ignore next */ []));
950
+ // `a[Button]` adalah komponen, jadi tanpa `read` query template-ref ini
951
+ // mengembalikan instance ButtonComponent — bukan elemen anchor-nya.
952
+ retryLink = viewChild('retryLink', { ...(ngDevMode ? { debugName: "retryLink" } : /* istanbul ignore next */ {}), read: ElementRef });
953
+ constructor() {
954
+ effect(() => {
955
+ if (this.state() !== 'error') {
956
+ return;
957
+ }
958
+ afterNextRender(() => this.retryLink()?.nativeElement.focus(), { injector: this.injector });
959
+ });
960
+ this.handleCallback();
961
+ }
962
+ handleCallback() {
963
+ const queryParams = this.route.snapshot.queryParamMap;
964
+ const oauthError = queryParams.get('error')?.trim() ?? '';
965
+ const code = queryParams.get('code')?.trim() ?? '';
966
+ const returnedState = queryParams.get('state')?.trim() ?? '';
967
+ // State dikonsumsi (dibaca + dihapus) sebelum bercabang supaya bersih di
968
+ // semua cabang, termasuk cabang error dari Google.
969
+ const storedState = consumeGoogleOauthState(this.documentRef);
970
+ this.clearCallbackParamsFromAddressBar();
971
+ if (oauthError) {
972
+ this.fail(oauthError === 'access_denied'
973
+ ? this.messages.google.googleAccessDenied
974
+ : this.messages.google.googleCallbackError);
975
+ return;
976
+ }
977
+ if (!returnedState || !storedState || returnedState !== storedState) {
978
+ this.fail(this.messages.google.googleStateMismatch);
979
+ return;
980
+ }
981
+ if (!code) {
982
+ this.fail(this.messages.google.googleCallbackError);
983
+ return;
984
+ }
985
+ this.exchange(code);
986
+ }
987
+ clearCallbackParamsFromAddressBar() {
988
+ this.location.replaceState(`/${GOOGLE_OAUTH_CALLBACK_ROUTE_PATH}`);
989
+ }
990
+ exchange(code) {
991
+ const googleOauth = this.authConfig.oauth.google;
992
+ if (!googleOauth) {
993
+ this.fail(this.messages.google.googleCallbackError);
994
+ return;
995
+ }
996
+ this.state.set('pending');
997
+ this.message.set(this.messages.google.googleExchangeInProgress);
998
+ // Exchange lewat method SDK hasil generate (konsisten dengan
999
+ // verifyMagicLink/refreshAuthToken); path /v1/auth/google membuat
1000
+ // edsisAuthInterceptor otomatis memasang cookie credentials.
1001
+ this.authSessionService
1002
+ .exchangeGoogleCode({
1003
+ body: { code, redirectUri: googleOauth.redirectUri },
1004
+ })
1005
+ .pipe(takeUntilDestroyed(this.destroyRef))
1006
+ .subscribe({
1007
+ next: (response) => {
1008
+ const session = persistSession(this.documentRef, response.data);
1009
+ if (!session) {
1010
+ this.fail(this.messages.google.missingAccessToken);
1011
+ return;
1012
+ }
1013
+ this.state.set('success');
1014
+ this.message.set(getResponseMessage(response, this.messages.google.successRedirect));
1015
+ void this.router.navigateByUrl(this.authenticatedHomePath, { replaceUrl: true });
1016
+ },
1017
+ error: (error) => {
1018
+ this.fail(getBackendErrorMessage(error, this.messages.google.googleCallbackError));
1019
+ },
1020
+ });
1021
+ }
1022
+ fail(message) {
1023
+ this.state.set('error');
1024
+ this.message.set(message);
1025
+ }
1026
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleCallbackPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
1027
+ 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: `
1028
+ <Card
1029
+ class="w-full overflow-hidden rounded-none border-border/80 bg-card/95 shadow-2xl backdrop-blur-sm"
1030
+ >
1031
+ <CardHeader
1032
+ 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"
1033
+ >
1034
+ <div class="w-16 shrink-0 sm:w-20">
1035
+ <AspectRatio [ratio]="3 / 2" class="overflow-hidden rounded-none bg-primary">
1036
+ <div
1037
+ 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]"
1038
+ style="font-family: 'Arial Black', Arial, sans-serif;"
1039
+ >
1040
+ {{ messages.brand.mark }}
1041
+ </div>
1042
+ </AspectRatio>
1043
+ </div>
1044
+ <div class="min-w-0 space-y-0.5 pt-0.5 sm:pt-1">
1045
+ <CardTitle class="text-xl leading-tight sm:text-2xl">{{
1046
+ messages.google.title
1047
+ }}</CardTitle>
1048
+ <p CardDescription class="max-w-xl leading-6">
1049
+ {{ messages.google.intro }}
1050
+ </p>
1051
+ </div>
1052
+ <CardAction
1053
+ 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"
1054
+ >
1055
+ {{ messages.google.badge }}
1056
+ </CardAction>
1057
+ </CardHeader>
1058
+
1059
+ <CardContent class="space-y-4 pt-6 sm:pt-7">
1060
+ <Alert
1061
+ [variant]="state() === 'error' ? 'destructive' : 'default'"
1062
+ class="bg-background/70 shadow-sm"
1063
+ >
1064
+ @if (state() === 'pending') {
1065
+ <Spinner class="mt-0.5 size-4" [aria-label]="messages.google.exchangeInProgressAria" />
1066
+ }
1067
+
1068
+ <AlertDescription>
1069
+ {{ message() }}
1070
+ </AlertDescription>
1071
+ </Alert>
1072
+ </CardContent>
1073
+
1074
+ @if (state() !== 'pending') {
1075
+ <CardFooter class="flex flex-wrap gap-3 border-t border-border/60 bg-muted/10 pt-4 sm:pt-5">
1076
+ @if (state() === 'error') {
1077
+ <a #retryLink Button [routerLink]="loginPath" variant="default">
1078
+ {{ messages.google.googleRetry }}
1079
+ </a>
1080
+ }
1081
+ <a
1082
+ Button
1083
+ [routerLink]="authenticatedHomePath"
1084
+ [variant]="state() === 'error' ? 'outline' : 'default'"
1085
+ >
1086
+ {{ messages.google.openDashboard }}
1087
+ </a>
1088
+ </CardFooter>
1089
+ }
1090
+ </Card>
1091
+ `, 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"] }] });
1092
+ }
1093
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: AuthGoogleCallbackPage, decorators: [{
1094
+ type: Component,
1095
+ args: [{
1096
+ selector: 'AuthGoogleCallbackPage',
1097
+ imports: [
1098
+ RouterLink,
1099
+ AlertComponent,
1100
+ AlertDescriptionComponent,
1101
+ AspectRatioComponent,
1102
+ ButtonComponent,
1103
+ CardActionComponent,
1104
+ CardComponent,
1105
+ CardContentComponent,
1106
+ CardDescriptionComponent,
1107
+ CardFooterComponent,
1108
+ CardHeaderComponent,
1109
+ CardTitleComponent,
1110
+ SpinnerComponent,
1111
+ ],
1112
+ host: {
1113
+ class: 'block',
1114
+ },
1115
+ template: `
1116
+ <Card
1117
+ class="w-full overflow-hidden rounded-none border-border/80 bg-card/95 shadow-2xl backdrop-blur-sm"
1118
+ >
1119
+ <CardHeader
1120
+ 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"
1121
+ >
1122
+ <div class="w-16 shrink-0 sm:w-20">
1123
+ <AspectRatio [ratio]="3 / 2" class="overflow-hidden rounded-none bg-primary">
1124
+ <div
1125
+ 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]"
1126
+ style="font-family: 'Arial Black', Arial, sans-serif;"
1127
+ >
1128
+ {{ messages.brand.mark }}
1129
+ </div>
1130
+ </AspectRatio>
1131
+ </div>
1132
+ <div class="min-w-0 space-y-0.5 pt-0.5 sm:pt-1">
1133
+ <CardTitle class="text-xl leading-tight sm:text-2xl">{{
1134
+ messages.google.title
1135
+ }}</CardTitle>
1136
+ <p CardDescription class="max-w-xl leading-6">
1137
+ {{ messages.google.intro }}
1138
+ </p>
1139
+ </div>
1140
+ <CardAction
1141
+ 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"
1142
+ >
1143
+ {{ messages.google.badge }}
1144
+ </CardAction>
1145
+ </CardHeader>
1146
+
1147
+ <CardContent class="space-y-4 pt-6 sm:pt-7">
1148
+ <Alert
1149
+ [variant]="state() === 'error' ? 'destructive' : 'default'"
1150
+ class="bg-background/70 shadow-sm"
1151
+ >
1152
+ @if (state() === 'pending') {
1153
+ <Spinner class="mt-0.5 size-4" [aria-label]="messages.google.exchangeInProgressAria" />
1154
+ }
1155
+
1156
+ <AlertDescription>
1157
+ {{ message() }}
1158
+ </AlertDescription>
1159
+ </Alert>
1160
+ </CardContent>
1161
+
1162
+ @if (state() !== 'pending') {
1163
+ <CardFooter class="flex flex-wrap gap-3 border-t border-border/60 bg-muted/10 pt-4 sm:pt-5">
1164
+ @if (state() === 'error') {
1165
+ <a #retryLink Button [routerLink]="loginPath" variant="default">
1166
+ {{ messages.google.googleRetry }}
1167
+ </a>
1168
+ }
1169
+ <a
1170
+ Button
1171
+ [routerLink]="authenticatedHomePath"
1172
+ [variant]="state() === 'error' ? 'outline' : 'default'"
1173
+ >
1174
+ {{ messages.google.openDashboard }}
1175
+ </a>
1176
+ </CardFooter>
1177
+ }
1178
+ </Card>
1179
+ `,
1180
+ }]
1181
+ }], ctorParameters: () => [], propDecorators: { retryLink: [{ type: i0.ViewChild, args: ['retryLink', { ...{ read: ElementRef }, isSignal: true }] }] } });
1182
+
861
1183
  class AuthLoginPage {
1184
+ documentRef = inject(DOCUMENT);
862
1185
  destroyRef = inject(DestroyRef);
863
1186
  formBuilder = inject(FormBuilder);
864
1187
  injector = inject(Injector);
@@ -866,6 +1189,9 @@ class AuthLoginPage {
866
1189
  authConfig = inject(EDSIS_AUTH_CONFIG);
867
1190
  messages = inject(EDSIS_AUTH_MESSAGES);
868
1191
  health = inject(AuthHealthService);
1192
+ googleOauth = this.authConfig.oauth.google;
1193
+ isGoogleRedirecting = signal(false, /* @ts-ignore */
1194
+ ...(ngDevMode ? [{ debugName: "isGoogleRedirecting" }] : /* istanbul ignore next */ []));
869
1195
  form = this.formBuilder.nonNullable.group({
870
1196
  email: ['', [Validators.required, Validators.email, Validators.maxLength(255)]],
871
1197
  });
@@ -878,8 +1204,9 @@ class AuthLoginPage {
878
1204
  emailControl = this.form.controls.email;
879
1205
  emailFeedbackId = 'email-feedback';
880
1206
  healthBannerId = 'auth-health-banner';
881
- retryButton = viewChild('healthRetryButton', /* @ts-ignore */
882
- ...(ngDevMode ? [{ debugName: "retryButton" }] : /* istanbul ignore next */ []));
1207
+ // `button[Button]` adalah komponen, jadi tanpa `read` query template-ref ini
1208
+ // mengembalikan instance ButtonComponent — bukan elemen button-nya.
1209
+ retryButton = viewChild('healthRetryButton', { ...(ngDevMode ? { debugName: "retryButton" } : /* istanbul ignore next */ {}), read: ElementRef });
883
1210
  emailControlState = toSignal(this.emailControl.events.pipe(startWith(null)), {
884
1211
  initialValue: null,
885
1212
  });
@@ -948,6 +1275,26 @@ class AuthLoginPage {
948
1275
  retryHealth() {
949
1276
  void this.health.check();
950
1277
  }
1278
+ signInWithGoogle() {
1279
+ const googleOauth = this.googleOauth;
1280
+ const windowRef = this.documentRef.defaultView;
1281
+ if (!googleOauth || !windowRef || this.isGoogleRedirecting()) {
1282
+ return;
1283
+ }
1284
+ this.isGoogleRedirecting.set(true);
1285
+ const state = createGoogleOauthState(windowRef);
1286
+ storeGoogleOauthState(this.documentRef, state);
1287
+ this.redirectTo(buildGoogleAuthorizeUrl({
1288
+ clientId: googleOauth.clientId,
1289
+ redirectUri: googleOauth.redirectUri,
1290
+ state,
1291
+ }));
1292
+ }
1293
+ // Full-page redirect keluar dari SPA (bukan Router). Method terpisah karena
1294
+ // jsdom tidak mengizinkan stub pada location.assign.
1295
+ redirectTo(url) {
1296
+ this.documentRef.defaultView?.location.assign(url);
1297
+ }
951
1298
  async submit() {
952
1299
  if (this.form.invalid) {
953
1300
  this.form.markAllAsTouched();
@@ -964,10 +1311,7 @@ class AuthLoginPage {
964
1311
  this.emailControl.setValue(email);
965
1312
  this.authMagicLinkService
966
1313
  .requestMagicLoginLink({
967
- body: {
968
- email,
969
- frontend_url: buildVerifyUrl(this.authConfig),
970
- },
1314
+ body: { email },
971
1315
  })
972
1316
  .pipe(takeUntilDestroyed(this.destroyRef), finalize(() => this.isSubmitting.set(false)))
973
1317
  .subscribe({
@@ -980,7 +1324,7 @@ class AuthLoginPage {
980
1324
  });
981
1325
  }
982
1326
  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: `
1327
+ 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
1328
  <Card
985
1329
  class="w-full overflow-hidden rounded-none border-border/80 bg-card/95 shadow-2xl backdrop-blur-sm"
986
1330
  >
@@ -1116,9 +1460,10 @@ class AuthLoginPage {
1116
1460
  type="button"
1117
1461
  variant="outline"
1118
1462
  size="lg"
1119
- disabled
1120
- [attr.aria-label]="messages.login.oauthGoogleAria"
1121
- [attr.title]="messages.login.oauthComingSoon"
1463
+ [disabled]="!googleOauth || isGoogleRedirecting()"
1464
+ [attr.aria-label]="googleOauth ? messages.google.signInAria : messages.login.oauthGoogleAria"
1465
+ [attr.title]="googleOauth ? null : messages.login.oauthComingSoon"
1466
+ (click)="signInWithGoogle()"
1122
1467
  class="h-12 gap-3 text-[0.74rem] font-medium uppercase tracking-[0.16em]"
1123
1468
  >
1124
1469
  <span
@@ -1144,7 +1489,7 @@ class AuthLoginPage {
1144
1489
  />
1145
1490
  </svg>
1146
1491
  </span>
1147
- Google
1492
+ {{ isGoogleRedirecting() ? messages.google.googleRedirecting : 'Google' }}
1148
1493
  </button>
1149
1494
  <button
1150
1495
  Button
@@ -1196,6 +1541,12 @@ class AuthLoginPage {
1196
1541
  Apple
1197
1542
  </button>
1198
1543
  </div>
1544
+
1545
+ @if (isGoogleRedirecting()) {
1546
+ <p class="sr-only" role="status" aria-live="polite">
1547
+ {{ messages.google.googleRedirecting }}
1548
+ </p>
1549
+ }
1199
1550
  </form>
1200
1551
  </CardContent>
1201
1552
  </Card>
@@ -1361,9 +1712,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1361
1712
  type="button"
1362
1713
  variant="outline"
1363
1714
  size="lg"
1364
- disabled
1365
- [attr.aria-label]="messages.login.oauthGoogleAria"
1366
- [attr.title]="messages.login.oauthComingSoon"
1715
+ [disabled]="!googleOauth || isGoogleRedirecting()"
1716
+ [attr.aria-label]="googleOauth ? messages.google.signInAria : messages.login.oauthGoogleAria"
1717
+ [attr.title]="googleOauth ? null : messages.login.oauthComingSoon"
1718
+ (click)="signInWithGoogle()"
1367
1719
  class="h-12 gap-3 text-[0.74rem] font-medium uppercase tracking-[0.16em]"
1368
1720
  >
1369
1721
  <span
@@ -1389,7 +1741,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1389
1741
  />
1390
1742
  </svg>
1391
1743
  </span>
1392
- Google
1744
+ {{ isGoogleRedirecting() ? messages.google.googleRedirecting : 'Google' }}
1393
1745
  </button>
1394
1746
  <button
1395
1747
  Button
@@ -1441,12 +1793,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
1441
1793
  Apple
1442
1794
  </button>
1443
1795
  </div>
1796
+
1797
+ @if (isGoogleRedirecting()) {
1798
+ <p class="sr-only" role="status" aria-live="polite">
1799
+ {{ messages.google.googleRedirecting }}
1800
+ </p>
1801
+ }
1444
1802
  </form>
1445
1803
  </CardContent>
1446
1804
  </Card>
1447
1805
  `,
1448
1806
  }]
1449
- }], ctorParameters: () => [], propDecorators: { retryButton: [{ type: i0.ViewChild, args: ['healthRetryButton', { isSignal: true }] }] } });
1807
+ }], ctorParameters: () => [], propDecorators: { retryButton: [{ type: i0.ViewChild, args: ['healthRetryButton', { ...{ read: ElementRef }, isSignal: true }] }] } });
1450
1808
 
1451
1809
  class AuthLogoutPage {
1452
1810
  destroyRef = inject(DestroyRef);
@@ -1888,6 +2246,12 @@ const authRoutes = [
1888
2246
  canActivate: [guestOnlyGuard],
1889
2247
  component: AuthLoginPage,
1890
2248
  },
2249
+ {
2250
+ path: GOOGLE_OAUTH_CALLBACK_ROUTE_PATH,
2251
+ title: 'Google Sign-In',
2252
+ canActivate: [guestOnlyGuard],
2253
+ component: AuthGoogleCallbackPage,
2254
+ },
1891
2255
  {
1892
2256
  path: 'logout',
1893
2257
  title: 'Logout',
@@ -1907,5 +2271,5 @@ const authRoutes = [
1907
2271
  * Generated bundle index. Do not edit.
1908
2272
  */
1909
2273
 
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 };
2274
+ export { AUTH_SESSION_CHANGE_EVENT, AuthGoogleCallbackPage, 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
2275
  //# sourceMappingURL=edsis-angular-module-auth.mjs.map