@edsis/angular 22.0.70 → 22.0.72

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,8 +1,9 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, inject, signal, computed, Injectable, makeEnvironmentProviders, provideAppInitializer, Component, DestroyRef, Injector, viewChild, ElementRef, effect, afterNextRender, input } from '@angular/core';
2
+ import { InjectionToken, Injectable, inject, signal, computed, makeEnvironmentProviders, provideAppInitializer, Component, DestroyRef, Injector, viewChild, ElementRef, effect, afterNextRender, input } from '@angular/core';
3
3
  import { HttpClient, HttpErrorResponse, HttpContextToken, HttpContext, provideHttpClient, withFetch, withInterceptors } from '@angular/common/http';
4
4
  import { provideApiConfiguration } from '@edsis/sdk/shared';
5
5
  import { Router, RouterOutlet, ActivatedRoute, RouterLink } from '@angular/router';
6
+ import { setNativeNotificationBadge, RuntimeContextService } from '@edsis/angular/services/runtime';
6
7
  import { firstValueFrom, throwError, from, timeout, startWith, finalize } from 'rxjs';
7
8
  import { catchError, switchMap } from 'rxjs/operators';
8
9
  import { LayoutComponent, LayoutFluidComponent } from '@edsis/theme/layout';
@@ -57,9 +58,22 @@ function resolveEdsisAuthConfig(config) {
57
58
  redirectUri: `${appUrl}/${GOOGLE_OAUTH_CALLBACK_ROUTE_PATH}`,
58
59
  }
59
60
  : null,
61
+ nativeGoogle: config.oauth?.nativeGoogle && config.oauth.nativeGoogle.enabled !== false
62
+ ? { apiUrl: normalizeSameOriginPath(config.oauth.nativeGoogle.apiUrl ?? '/api') }
63
+ : null,
60
64
  },
61
65
  };
62
66
  }
67
+ function normalizeSameOriginPath(value) {
68
+ const normalizedValue = value.trim().replace(/\/+$/u, '');
69
+ if (!normalizedValue.startsWith('/') ||
70
+ normalizedValue.startsWith('//') ||
71
+ normalizedValue.includes('?') ||
72
+ normalizedValue.includes('#')) {
73
+ throw new Error('Edsis native Google auth requires a same-origin apiUrl path.');
74
+ }
75
+ return (normalizedValue || '/');
76
+ }
63
77
  function normalizeAbsoluteUrl(value, label) {
64
78
  const normalizedValue = value.trim();
65
79
  if (!normalizedValue) {
@@ -106,6 +120,9 @@ const DEFAULT_EDSIS_AUTH_MESSAGES = {
106
120
  badge: 'GOOGLE',
107
121
  signInAria: 'Login dengan Google',
108
122
  googleRedirecting: 'Mengarahkan ke Google...',
123
+ nativeSignInInProgress: 'Menyelesaikan login Google di perangkat...',
124
+ nativeSignInUnavailable: 'Google Sign-In native tidak tersedia pada perangkat ini. Perbarui aplikasi atau hubungi administrator.',
125
+ nativeSignInFailed: 'Login Google pada perangkat gagal diproses.',
109
126
  googleExchangeInProgress: 'Menukar kode otorisasi Google...',
110
127
  exchangeInProgressAria: 'Menukar kode otorisasi Google',
111
128
  googleStateMismatch: 'Verifikasi keamanan gagal: state OAuth tidak cocok atau hilang. Silakan ulangi login dari awal.',
@@ -158,10 +175,43 @@ function mergeEdsisAuthMessages(override) {
158
175
  };
159
176
  }
160
177
 
178
+ const EDSIS_NATIVE_GOOGLE_AUTH_ADAPTER = new InjectionToken('EDSIS_NATIVE_GOOGLE_AUTH_ADAPTER');
179
+ class TauriNativeGoogleAuthAdapter {
180
+ async signInWithGoogle(input) {
181
+ const { invoke } = await import('@tauri-apps/api/core');
182
+ const response = await invoke('plugin:edsis-google-auth|sign_in', {
183
+ nonce: input.nonce,
184
+ });
185
+ if (!isNativeGoogleSignInResult(response)) {
186
+ throw new Error('Native Google Sign-In returned an invalid response.');
187
+ }
188
+ return response;
189
+ }
190
+ async signOutFromGoogle() {
191
+ const { invoke } = await import('@tauri-apps/api/core');
192
+ await invoke('plugin:edsis-google-auth|sign_out');
193
+ }
194
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: TauriNativeGoogleAuthAdapter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
195
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: TauriNativeGoogleAuthAdapter });
196
+ }
197
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: TauriNativeGoogleAuthAdapter, decorators: [{
198
+ type: Injectable
199
+ }] });
200
+ function isNativeGoogleSignInResult(value) {
201
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
202
+ return false;
203
+ }
204
+ const result = value;
205
+ return ((result['platform'] === 'ios' || result['platform'] === 'android') &&
206
+ typeof result['idToken'] === 'string' &&
207
+ result['idToken'].trim().length > 0 &&
208
+ typeof result['clientInstanceId'] === 'string' &&
209
+ result['clientInstanceId'].trim().length > 0);
210
+ }
211
+
161
212
  /** Native desktop features are optional; browser consumers have no bridge. */
162
213
  async function setAuthNotificationBadge(unreadCount) {
163
- const desktop = typeof window === 'undefined' ? undefined : window.EDSIS_DESKTOP;
164
- await desktop?.setNotificationBadge(unreadCount);
214
+ await setNativeNotificationBadge(unreadCount);
165
215
  }
166
216
  /**
167
217
  * Cookie-backed authentication state. The access token intentionally exists
@@ -172,12 +222,16 @@ class AuthService {
172
222
  http = inject(HttpClient);
173
223
  config = inject(EDSIS_AUTH_CONFIG);
174
224
  router = inject(Router, { optional: true });
225
+ runtime = inject(RuntimeContextService, { optional: true });
226
+ nativeGoogleAdapter = inject(EDSIS_NATIVE_GOOGLE_AUTH_ADAPTER, {
227
+ optional: true,
228
+ });
175
229
  accessTokenState = signal('', /* @ts-ignore */
176
230
  ...(ngDevMode ? [{ debugName: "accessTokenState" }] : /* istanbul ignore next */ []));
177
231
  userState = signal(null, /* @ts-ignore */
178
232
  ...(ngDevMode ? [{ debugName: "userState" }] : /* istanbul ignore next */ []));
179
233
  refreshInFlight = null;
180
- initialized = false;
234
+ initialization = null;
181
235
  accessToken = this.accessTokenState.asReadonly();
182
236
  user = this.userState.asReadonly();
183
237
  isAuthenticated = computed(() => Boolean(this.accessTokenState()), /* @ts-ignore */
@@ -185,26 +239,23 @@ class AuthService {
185
239
  get apiUrl() {
186
240
  return this.config.apiUrl.replace(/\/+$/u, '');
187
241
  }
188
- async login(credentials) {
189
- const email = credentials.email?.trim();
190
- const username = credentials.username?.trim();
191
- if (Boolean(email) === Boolean(username)) {
192
- throw new Error('Auth login requires exactly one of email or username.');
193
- }
194
- const response = await firstValueFrom(this.http.post(`${this.apiUrl}/api/auth/login`, {
195
- ...(email ? { email } : { username }),
196
- password: credentials.password,
197
- ...(credentials.deviceType ? { deviceType: credentials.deviceType } : {}),
198
- }, { withCredentials: true }));
199
- this.applyTokenResponse(response);
200
- return this.loadCurrentUser();
242
+ get sessionApiUrl() {
243
+ const nativeApiUrl = this.config.oauth.nativeGoogle?.apiUrl;
244
+ return this.runtime?.isTabletShell() === true && nativeApiUrl
245
+ ? nativeApiUrl.replace(/\/+$/u, '')
246
+ : this.apiUrl;
201
247
  }
202
248
  /** Restores an existing cookie session. A missing/expired cookie is normal. */
203
- async initialize() {
204
- if (this.initialized) {
205
- return;
249
+ initialize() {
250
+ this.initialization ??= this.restoreSession();
251
+ return this.initialization;
252
+ }
253
+ async restoreSession() {
254
+ // Runtime selection must settle before choosing the cookie origin. Angular
255
+ // app initializers run concurrently, so auth cannot rely on provider order.
256
+ if (this.runtime) {
257
+ await this.runtime.initialize();
206
258
  }
207
- this.initialized = true;
208
259
  if (await this.refresh()) {
209
260
  try {
210
261
  await this.loadCurrentUser();
@@ -226,7 +277,7 @@ class AuthService {
226
277
  if (this.refreshInFlight) {
227
278
  return this.refreshInFlight;
228
279
  }
229
- this.refreshInFlight = firstValueFrom(this.http.post(`${this.apiUrl}/api/auth/refresh`, null, {
280
+ this.refreshInFlight = firstValueFrom(this.http.post(`${this.sessionApiUrl}/v1/auth/refresh`, null, {
230
281
  withCredentials: true,
231
282
  }))
232
283
  .then((response) => {
@@ -251,7 +302,7 @@ class AuthService {
251
302
  if (!token) {
252
303
  return null;
253
304
  }
254
- const response = await firstValueFrom(this.http.get(`${this.apiUrl}/api/auth/me`, {
305
+ const response = await firstValueFrom(this.http.get(`${this.sessionApiUrl}/v1/auth/me`, {
255
306
  withCredentials: true,
256
307
  headers: { Authorization: `Bearer ${token}` },
257
308
  }));
@@ -261,10 +312,11 @@ class AuthService {
261
312
  }
262
313
  async logout() {
263
314
  try {
264
- await firstValueFrom(this.http.post(`${this.apiUrl}/api/auth/logout`, null, { withCredentials: true }));
315
+ await firstValueFrom(this.http.post(`${this.sessionApiUrl}/v1/auth/logout`, null, { withCredentials: true }));
265
316
  }
266
317
  finally {
267
318
  this.clearSession();
319
+ await this.clearNativeGoogleSession();
268
320
  }
269
321
  }
270
322
  clearSession() {
@@ -285,13 +337,27 @@ class AuthService {
285
337
  const isPersistentResponse = 'accessToken' in response;
286
338
  const token = isPersistentResponse
287
339
  ? response.accessToken
288
- : response.access_token ?? response.data?.access_token;
340
+ : (response.access_token ?? response.data?.access_token);
289
341
  this.accessTokenState.set(typeof token === 'string' ? token : '');
290
- const user = isPersistentResponse ? response.user : response.user ?? response.data?.user;
342
+ const user = isPersistentResponse ? response.user : (response.user ?? response.data?.user);
291
343
  if (user) {
292
344
  this.userState.set(user);
293
345
  }
294
346
  }
347
+ async clearNativeGoogleSession() {
348
+ if (!this.nativeGoogleAdapter ||
349
+ this.runtime?.isTabletShell() !== true ||
350
+ !this.runtime.supports('google-native-sign-in')) {
351
+ return;
352
+ }
353
+ try {
354
+ await this.nativeGoogleAdapter.signOutFromGoogle();
355
+ }
356
+ catch {
357
+ // Backend logout and memory cleanup remain authoritative. A native SDK
358
+ // sign-out failure must not restore or persist the application session.
359
+ }
360
+ }
295
361
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: AuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
296
362
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: AuthService, providedIn: 'root' });
297
363
  }
@@ -302,17 +368,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
302
368
 
303
369
  const EDSIS_SKIP_AUTH = new HttpContextToken(() => false);
304
370
  const EDSIS_AUTH_RETRY = new HttpContextToken(() => false);
305
- const AUTH_ENDPOINTS = new Set(['/api/auth/login', '/api/auth/refresh', '/api/auth/logout']);
371
+ const AUTH_ENDPOINTS = new Set(['/v1/auth/login', '/v1/auth/refresh', '/v1/auth/logout']);
306
372
  function apiPath(url, apiUrl) {
307
373
  // A consumer may use Angular's same-origin dev/prod proxy (`/api/...`) even
308
374
  // when `apiUrl` names the upstream origin. Such relative URLs are API calls.
309
375
  if (url.startsWith('/')) {
310
- return url.split(/[?#]/, 1)[0] ?? url;
376
+ const path = url.split(/[?#]/, 1)[0] ?? url;
377
+ return path === '/api' || path.startsWith('/api/') ? path : null;
311
378
  }
312
379
  try {
313
380
  const resolved = new URL(url);
314
381
  const api = new URL(apiUrl);
315
- return resolved.origin === api.origin ? resolved.pathname : null;
382
+ if (resolved.origin !== api.origin)
383
+ return null;
384
+ const apiBasePath = api.pathname.replace(/\/+$/u, '') || '/';
385
+ if (apiBasePath !== '/' &&
386
+ resolved.pathname !== apiBasePath &&
387
+ !resolved.pathname.startsWith(`${apiBasePath}/`)) {
388
+ return null;
389
+ }
390
+ return resolved.pathname;
316
391
  }
317
392
  catch {
318
393
  return null;
@@ -334,13 +409,16 @@ const edsisAuthInterceptor = (request, next) => {
334
409
  return next(request);
335
410
  }
336
411
  const path = apiPath(request.url, auth.apiUrl);
337
- const isAuthEndpoint = AUTH_ENDPOINTS.has(path ?? '') || path?.startsWith('/v1/auth/');
412
+ const normalizedAuthPath = path?.startsWith('/api/') ? path.slice(4) : path;
413
+ const isAuthEndpoint = AUTH_ENDPOINTS.has(normalizedAuthPath ?? '') || normalizedAuthPath?.startsWith('/v1/auth/');
338
414
  const prepared = authorize(request, isAuthEndpoint ? '' : auth.accessToken());
339
415
  if (isAuthEndpoint) {
340
416
  return next(prepared);
341
417
  }
342
418
  return next(prepared).pipe(catchError((error) => {
343
- if (!(error instanceof HttpErrorResponse) || error.status !== 401 || request.context.get(EDSIS_AUTH_RETRY)) {
419
+ if (!(error instanceof HttpErrorResponse) ||
420
+ error.status !== 401 ||
421
+ request.context.get(EDSIS_AUTH_RETRY)) {
344
422
  return throwError(() => error);
345
423
  }
346
424
  return from(auth.refresh()).pipe(switchMap((refreshed) => {
@@ -408,6 +486,98 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
408
486
  type: Injectable
409
487
  }] });
410
488
 
489
+ class NativeGoogleAuthService {
490
+ http = inject(HttpClient);
491
+ auth = inject(AuthService);
492
+ config = inject(EDSIS_AUTH_CONFIG);
493
+ runtime = inject(RuntimeContextService, { optional: true });
494
+ adapter = inject(EDSIS_NATIVE_GOOGLE_AUTH_ADAPTER);
495
+ requiresNativeGoogle = computed(() => this.runtime?.isTabletShell() === true, /* @ts-ignore */
496
+ ...(ngDevMode ? [{ debugName: "requiresNativeGoogle" }] : /* istanbul ignore next */ []));
497
+ isAvailable = computed(() => {
498
+ const runtime = this.runtime;
499
+ return (this.config.oauth.nativeGoogle !== null &&
500
+ runtime?.isTabletShell() === true &&
501
+ toNativePlatform(runtime.context().platform) !== null &&
502
+ runtime.supports('google-native-sign-in'));
503
+ }, /* @ts-ignore */
504
+ ...(ngDevMode ? [{ debugName: "isAvailable" }] : /* istanbul ignore next */ []));
505
+ async signIn() {
506
+ const nativeConfig = this.config.oauth.nativeGoogle;
507
+ const platform = toNativePlatform(this.runtime?.context().platform);
508
+ if (!nativeConfig || !platform || !this.isAvailable()) {
509
+ throw new Error('Native Google Sign-In is not available in this runtime.');
510
+ }
511
+ const challengeResponse = await firstValueFrom(this.http.post(`${nativeConfig.apiUrl}/v1/auth/google/native/challenge`, { platform, deviceType: 'tablet' }, { withCredentials: true }));
512
+ const challenge = parseChallenge(challengeResponse);
513
+ const response = await this.exchangeNativeToken(nativeConfig.apiUrl, platform, challenge);
514
+ this.auth.acceptTokenResponse(response);
515
+ if (!this.auth.isAuthenticated()) {
516
+ throw new Error('Native Google Sign-In response did not contain an access token.');
517
+ }
518
+ try {
519
+ await this.auth.loadCurrentUser();
520
+ }
521
+ catch (error) {
522
+ this.auth.clearSession();
523
+ throw error;
524
+ }
525
+ }
526
+ async exchangeNativeToken(apiUrl, platform, challenge) {
527
+ let nativeResult = await this.adapter.signInWithGoogle({
528
+ nonce: challenge.nonce,
529
+ });
530
+ if (nativeResult.platform !== platform) {
531
+ throw new Error('Native Google Sign-In platform does not match the runtime.');
532
+ }
533
+ const clientInstanceId = nativeResult.clientInstanceId;
534
+ let idToken = nativeResult.idToken;
535
+ nativeResult = null;
536
+ try {
537
+ return await firstValueFrom(this.http.post(`${apiUrl}/v1/auth/google/native`, {
538
+ platform,
539
+ idToken,
540
+ challengeId: challenge.challengeId,
541
+ clientInstanceId,
542
+ deviceType: 'tablet',
543
+ }, { withCredentials: true }));
544
+ }
545
+ finally {
546
+ // Strings cannot be zeroized in JavaScript, but dropping both local
547
+ // references immediately after the HTTPS exchange keeps the ID token
548
+ // outside application state and shortens its lifetime in the WebView.
549
+ idToken = '';
550
+ }
551
+ }
552
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: NativeGoogleAuthService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
553
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: NativeGoogleAuthService });
554
+ }
555
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImport: i0, type: NativeGoogleAuthService, decorators: [{
556
+ type: Injectable
557
+ }] });
558
+ function toNativePlatform(platform) {
559
+ return platform === 'ios' || platform === 'android' ? platform : null;
560
+ }
561
+ function parseChallenge(value) {
562
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
563
+ throw new Error('Native Google challenge returned an invalid response.');
564
+ }
565
+ const challenge = value.data;
566
+ if (typeof challenge !== 'object' || challenge === null || Array.isArray(challenge)) {
567
+ throw new Error('Native Google challenge returned an invalid response.');
568
+ }
569
+ const challengeRecord = challenge;
570
+ const challengeId = challengeRecord['challengeId'];
571
+ const nonce = challengeRecord['nonce'];
572
+ if (typeof challengeId !== 'string' ||
573
+ !challengeId.trim() ||
574
+ typeof nonce !== 'string' ||
575
+ !nonce.trim()) {
576
+ throw new Error('Native Google challenge returned an invalid response.');
577
+ }
578
+ return { challengeId, nonce };
579
+ }
580
+
411
581
  function provideEdsisAuth(config) {
412
582
  const resolvedConfig = resolveEdsisAuthConfig(config);
413
583
  return makeEnvironmentProviders([
@@ -424,6 +594,12 @@ function provideEdsisAuth(config) {
424
594
  useValue: mergeEdsisAuthMessages(config.messages),
425
595
  },
426
596
  AuthHealthService,
597
+ NativeGoogleAuthService,
598
+ TauriNativeGoogleAuthAdapter,
599
+ {
600
+ provide: EDSIS_NATIVE_GOOGLE_AUTH_ADAPTER,
601
+ useExisting: TauriNativeGoogleAuthAdapter,
602
+ },
427
603
  ]);
428
604
  }
429
605
 
@@ -842,11 +1018,30 @@ class AuthLoginPage {
842
1018
  injector = inject(Injector);
843
1019
  authMagicLinkService = inject(AuthMagicLinkService);
844
1020
  authConfig = inject(EDSIS_AUTH_CONFIG);
1021
+ nativeGoogle = inject(NativeGoogleAuthService, { optional: true });
1022
+ router = inject(Router, { optional: true });
845
1023
  messages = inject(EDSIS_AUTH_MESSAGES);
846
1024
  health = inject(AuthHealthService);
847
1025
  googleOauth = this.authConfig.oauth.google;
848
1026
  isGoogleRedirecting = signal(false, /* @ts-ignore */
849
1027
  ...(ngDevMode ? [{ debugName: "isGoogleRedirecting" }] : /* istanbul ignore next */ []));
1028
+ googleErrorMessage = signal(null, /* @ts-ignore */
1029
+ ...(ngDevMode ? [{ debugName: "googleErrorMessage" }] : /* istanbul ignore next */ []));
1030
+ requiresNativeGoogle = computed(() => this.nativeGoogle?.requiresNativeGoogle() === true, /* @ts-ignore */
1031
+ ...(ngDevMode ? [{ debugName: "requiresNativeGoogle" }] : /* istanbul ignore next */ []));
1032
+ isNativeGoogle = computed(() => this.nativeGoogle?.isAvailable() === true, /* @ts-ignore */
1033
+ ...(ngDevMode ? [{ debugName: "isNativeGoogle" }] : /* istanbul ignore next */ []));
1034
+ googleSignInAvailable = computed(() => this.isNativeGoogle() || (!this.requiresNativeGoogle() && this.googleOauth !== null), /* @ts-ignore */
1035
+ ...(ngDevMode ? [{ debugName: "googleSignInAvailable" }] : /* istanbul ignore next */ []));
1036
+ googleFeedbackMessage = computed(() => this.googleErrorMessage() ??
1037
+ (this.requiresNativeGoogle() && !this.isNativeGoogle()
1038
+ ? this.messages.google.nativeSignInUnavailable
1039
+ : null), /* @ts-ignore */
1040
+ ...(ngDevMode ? [{ debugName: "googleFeedbackMessage" }] : /* istanbul ignore next */ []));
1041
+ googleProgressMessage = computed(() => this.isNativeGoogle()
1042
+ ? this.messages.google.nativeSignInInProgress
1043
+ : this.messages.google.googleRedirecting, /* @ts-ignore */
1044
+ ...(ngDevMode ? [{ debugName: "googleProgressMessage" }] : /* istanbul ignore next */ []));
850
1045
  form = this.formBuilder.nonNullable.group({
851
1046
  email: ['', [Validators.required, Validators.email, Validators.maxLength(255)]],
852
1047
  });
@@ -931,11 +1126,24 @@ class AuthLoginPage {
931
1126
  void this.health.check();
932
1127
  }
933
1128
  signInWithGoogle() {
1129
+ if (this.isGoogleRedirecting()) {
1130
+ return;
1131
+ }
1132
+ if (this.requiresNativeGoogle()) {
1133
+ if (this.isNativeGoogle()) {
1134
+ void this.signInWithNativeGoogle();
1135
+ }
1136
+ else {
1137
+ this.googleErrorMessage.set(this.messages.google.nativeSignInUnavailable);
1138
+ }
1139
+ return;
1140
+ }
1141
+ if (!this.googleSignInAvailable())
1142
+ return;
934
1143
  const googleOauth = this.googleOauth;
935
1144
  const windowRef = this.documentRef.defaultView;
936
- if (!googleOauth || !windowRef || this.isGoogleRedirecting()) {
1145
+ if (!googleOauth || !windowRef)
937
1146
  return;
938
- }
939
1147
  this.isGoogleRedirecting.set(true);
940
1148
  const state = createGoogleOauthState(windowRef);
941
1149
  storeGoogleOauthState(this.documentRef, state);
@@ -945,6 +1153,24 @@ class AuthLoginPage {
945
1153
  state,
946
1154
  }));
947
1155
  }
1156
+ async signInWithNativeGoogle() {
1157
+ if (!this.nativeGoogle)
1158
+ return;
1159
+ this.isGoogleRedirecting.set(true);
1160
+ this.googleErrorMessage.set(null);
1161
+ try {
1162
+ await this.nativeGoogle.signIn();
1163
+ await this.router?.navigateByUrl(this.authConfig.authenticatedHomePath, {
1164
+ replaceUrl: true,
1165
+ });
1166
+ }
1167
+ catch {
1168
+ this.googleErrorMessage.set(this.messages.google.nativeSignInFailed);
1169
+ }
1170
+ finally {
1171
+ this.isGoogleRedirecting.set(false);
1172
+ }
1173
+ }
948
1174
  // Full-page redirect keluar dari SPA (bukan Router). Method terpisah karena
949
1175
  // jsdom tidak mengizinkan stub pada location.assign.
950
1176
  redirectTo(url) {
@@ -1120,11 +1346,21 @@ class AuthLoginPage {
1120
1346
  type="button"
1121
1347
  variant="outline"
1122
1348
  size="lg"
1123
- [disabled]="!googleOauth || isGoogleRedirecting()"
1349
+ [disabled]="!googleSignInAvailable() || isGoogleRedirecting()"
1124
1350
  [attr.aria-label]="
1125
- googleOauth ? messages.google.signInAria : messages.login.oauthGoogleAria
1351
+ googleSignInAvailable()
1352
+ ? messages.google.signInAria
1353
+ : requiresNativeGoogle()
1354
+ ? messages.google.nativeSignInUnavailable
1355
+ : messages.login.oauthGoogleAria
1356
+ "
1357
+ [attr.title]="
1358
+ googleSignInAvailable()
1359
+ ? null
1360
+ : requiresNativeGoogle()
1361
+ ? messages.google.nativeSignInUnavailable
1362
+ : messages.login.oauthComingSoon
1126
1363
  "
1127
- [attr.title]="googleOauth ? null : messages.login.oauthComingSoon"
1128
1364
  (click)="signInWithGoogle()"
1129
1365
  class="h-12 gap-3 text-[0.74rem] font-medium uppercase tracking-[0.16em]"
1130
1366
  >
@@ -1151,7 +1387,7 @@ class AuthLoginPage {
1151
1387
  />
1152
1388
  </svg>
1153
1389
  </span>
1154
- {{ isGoogleRedirecting() ? messages.google.googleRedirecting : 'Google' }}
1390
+ {{ isGoogleRedirecting() ? googleProgressMessage() : 'Google' }}
1155
1391
  </button>
1156
1392
  <button
1157
1393
  Button
@@ -1206,7 +1442,13 @@ class AuthLoginPage {
1206
1442
 
1207
1443
  @if (isGoogleRedirecting()) {
1208
1444
  <p class="sr-only" role="status" aria-live="polite">
1209
- {{ messages.google.googleRedirecting }}
1445
+ {{ googleProgressMessage() }}
1446
+ </p>
1447
+ }
1448
+
1449
+ @if (googleFeedbackMessage(); as googleError) {
1450
+ <p class="text-sm text-destructive" role="alert" aria-live="assertive">
1451
+ {{ googleError }}
1210
1452
  </p>
1211
1453
  }
1212
1454
  </form>
@@ -1376,11 +1618,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
1376
1618
  type="button"
1377
1619
  variant="outline"
1378
1620
  size="lg"
1379
- [disabled]="!googleOauth || isGoogleRedirecting()"
1621
+ [disabled]="!googleSignInAvailable() || isGoogleRedirecting()"
1380
1622
  [attr.aria-label]="
1381
- googleOauth ? messages.google.signInAria : messages.login.oauthGoogleAria
1623
+ googleSignInAvailable()
1624
+ ? messages.google.signInAria
1625
+ : requiresNativeGoogle()
1626
+ ? messages.google.nativeSignInUnavailable
1627
+ : messages.login.oauthGoogleAria
1628
+ "
1629
+ [attr.title]="
1630
+ googleSignInAvailable()
1631
+ ? null
1632
+ : requiresNativeGoogle()
1633
+ ? messages.google.nativeSignInUnavailable
1634
+ : messages.login.oauthComingSoon
1382
1635
  "
1383
- [attr.title]="googleOauth ? null : messages.login.oauthComingSoon"
1384
1636
  (click)="signInWithGoogle()"
1385
1637
  class="h-12 gap-3 text-[0.74rem] font-medium uppercase tracking-[0.16em]"
1386
1638
  >
@@ -1407,7 +1659,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
1407
1659
  />
1408
1660
  </svg>
1409
1661
  </span>
1410
- {{ isGoogleRedirecting() ? messages.google.googleRedirecting : 'Google' }}
1662
+ {{ isGoogleRedirecting() ? googleProgressMessage() : 'Google' }}
1411
1663
  </button>
1412
1664
  <button
1413
1665
  Button
@@ -1462,7 +1714,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.7", ngImpor
1462
1714
 
1463
1715
  @if (isGoogleRedirecting()) {
1464
1716
  <p class="sr-only" role="status" aria-live="polite">
1465
- {{ messages.google.googleRedirecting }}
1717
+ {{ googleProgressMessage() }}
1718
+ </p>
1719
+ }
1720
+
1721
+ @if (googleFeedbackMessage(); as googleError) {
1722
+ <p class="text-sm text-destructive" role="alert" aria-live="assertive">
1723
+ {{ googleError }}
1466
1724
  </p>
1467
1725
  }
1468
1726
  </form>
@@ -1935,5 +2193,5 @@ const authRoutes = [
1935
2193
  * Generated bundle index. Do not edit.
1936
2194
  */
1937
2195
 
1938
- export { AuthGoogleCallbackPage, AuthLoginPage, AuthLogoutPage, AuthService, AuthShellPage, AuthVerifyPage, DEFAULT_EDSIS_AUTH_MESSAGES, EDSIS_AUTH_CONFIG, EDSIS_AUTH_MESSAGES, EDSIS_SKIP_AUTH, GOOGLE_OAUTH_AUTHORIZE_URL, GOOGLE_OAUTH_CALLBACK_ROUTE_PATH, GOOGLE_OAUTH_STATE_STORAGE_KEY, authRoutes, authenticatedGuard, buildGoogleAuthorizeUrl, consumeGoogleOauthState, createGoogleOauthState, edsisAuthInterceptor, guestOnlyGuard, homeRedirectGuard, mergeEdsisAuthMessages, provideEdsisAuth, resolveEdsisAuthConfig, setAuthNotificationBadge, storeGoogleOauthState };
2196
+ export { AuthGoogleCallbackPage, AuthLoginPage, AuthLogoutPage, AuthService, AuthShellPage, AuthVerifyPage, DEFAULT_EDSIS_AUTH_MESSAGES, EDSIS_AUTH_CONFIG, EDSIS_AUTH_MESSAGES, EDSIS_NATIVE_GOOGLE_AUTH_ADAPTER, EDSIS_SKIP_AUTH, GOOGLE_OAUTH_AUTHORIZE_URL, GOOGLE_OAUTH_CALLBACK_ROUTE_PATH, GOOGLE_OAUTH_STATE_STORAGE_KEY, NativeGoogleAuthService, TauriNativeGoogleAuthAdapter, authRoutes, authenticatedGuard, buildGoogleAuthorizeUrl, consumeGoogleOauthState, createGoogleOauthState, edsisAuthInterceptor, guestOnlyGuard, homeRedirectGuard, isNativeGoogleSignInResult, mergeEdsisAuthMessages, provideEdsisAuth, resolveEdsisAuthConfig, setAuthNotificationBadge, storeGoogleOauthState };
1939
2197
  //# sourceMappingURL=edsis-angular-module-auth.mjs.map