@edsis/angular 21.0.0 → 21.1.1
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 +32 -3
- package/fesm2022/edsis-angular-auth.mjs +974 -0
- package/fesm2022/edsis-angular-auth.mjs.map +1 -0
- package/fesm2022/edsis-angular-sdk-access.mjs +15 -15
- package/fesm2022/edsis-angular-sdk-access.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-approval.mjs +15 -15
- package/fesm2022/edsis-angular-sdk-approval.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-auth.mjs +3 -3
- package/fesm2022/edsis-angular-sdk-auth.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-employee.mjs +3 -3
- package/fesm2022/edsis-angular-sdk-employee.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-health.mjs +3 -3
- package/fesm2022/edsis-angular-sdk-health.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-shared.mjs +9 -9
- package/fesm2022/edsis-angular-sdk-shared.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-storage.mjs +6 -6
- package/fesm2022/edsis-angular-sdk-storage.mjs.map +1 -1
- package/fesm2022/edsis-angular-sdk-user.mjs +3 -3
- package/fesm2022/edsis-angular-sdk-user.mjs.map +1 -1
- package/fesm2022/edsis-angular.mjs.map +1 -1
- package/package.json +5 -1
- package/types/edsis-angular-auth.d.ts +118 -0
|
@@ -0,0 +1,974 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, inject, makeEnvironmentProviders, ChangeDetectionStrategy, Component, DestroyRef, signal } from '@angular/core';
|
|
3
|
+
import { HttpContextToken, HttpErrorResponse, provideHttpClient, withFetch, withInterceptors } from '@angular/common/http';
|
|
4
|
+
import { ApiConfiguration, provideApiConfiguration } from '@edsis/angular/sdk/shared';
|
|
5
|
+
import { DOCUMENT, Location } from '@angular/common';
|
|
6
|
+
import { AuthService } from '@edsis/angular/sdk/auth';
|
|
7
|
+
import { firstValueFrom, throwError, from, finalize, combineLatest } from 'rxjs';
|
|
8
|
+
import { switchMap, catchError } from 'rxjs/operators';
|
|
9
|
+
import { Router, RouterOutlet, RouterLink, ActivatedRoute } from '@angular/router';
|
|
10
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
11
|
+
import * as i1 from '@angular/forms';
|
|
12
|
+
import { FormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
|
|
13
|
+
|
|
14
|
+
const DEFAULT_LOGIN_PATH = '/login';
|
|
15
|
+
const DEFAULT_LOGOUT_PATH = '/logout';
|
|
16
|
+
const DEFAULT_VERIFY_PATH = '/verify';
|
|
17
|
+
const DEFAULT_AUTHENTICATED_HOME_PATH = '/dashboard';
|
|
18
|
+
const EDSIS_AUTH_CONFIG = new InjectionToken('EDSIS_AUTH_CONFIG');
|
|
19
|
+
function resolveEdsisAuthConfig(config) {
|
|
20
|
+
const loginPath = normalizePath(config.loginPath, DEFAULT_LOGIN_PATH);
|
|
21
|
+
return {
|
|
22
|
+
apiUrl: normalizeAbsoluteUrl(config.apiUrl, 'apiUrl'),
|
|
23
|
+
appUrl: normalizeAbsoluteUrl(config.appUrl, 'appUrl'),
|
|
24
|
+
loginPath,
|
|
25
|
+
logoutPath: normalizePath(config.logoutPath, DEFAULT_LOGOUT_PATH),
|
|
26
|
+
verifyPath: normalizePath(config.verifyPath, DEFAULT_VERIFY_PATH),
|
|
27
|
+
authenticatedHomePath: normalizePath(config.authenticatedHomePath, DEFAULT_AUTHENTICATED_HOME_PATH),
|
|
28
|
+
guestHomePath: normalizePath(config.guestHomePath, loginPath),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function normalizeAbsoluteUrl(value, label) {
|
|
32
|
+
const normalizedValue = value.trim();
|
|
33
|
+
if (!normalizedValue) {
|
|
34
|
+
throw new Error(`Edsis auth requires a non-empty ${label}.`);
|
|
35
|
+
}
|
|
36
|
+
const normalizedUrl = new URL(normalizedValue);
|
|
37
|
+
return normalizedUrl.toString().replace(/\/$/, '');
|
|
38
|
+
}
|
|
39
|
+
function normalizePath(value, fallback) {
|
|
40
|
+
const normalizedValue = value?.trim();
|
|
41
|
+
if (!normalizedValue) {
|
|
42
|
+
return fallback;
|
|
43
|
+
}
|
|
44
|
+
return (normalizedValue.startsWith('/') ? normalizedValue : `/${normalizedValue}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const AUTH_SESSION_STORAGE_KEYS = ['access_token', 'user_id', 'role'];
|
|
48
|
+
const EMPTY_SESSION_FINGERPRINT = '__empty_session__';
|
|
49
|
+
const JWT_PART_COUNT = 3;
|
|
50
|
+
const TOKEN_EXPIRY_SKEW_MS = 30_000;
|
|
51
|
+
let validatedAccessToken = '';
|
|
52
|
+
let validatedUntilEpochMs = 0;
|
|
53
|
+
let failedSessionFingerprint = null;
|
|
54
|
+
let pendingSessionValidation = null;
|
|
55
|
+
function getSessionStorage(documentRef) {
|
|
56
|
+
return documentRef.defaultView?.sessionStorage ?? null;
|
|
57
|
+
}
|
|
58
|
+
function readSessionStorageValue(documentRef, storageKey) {
|
|
59
|
+
return getSessionStorage(documentRef)?.getItem(storageKey)?.trim() ?? '';
|
|
60
|
+
}
|
|
61
|
+
function readSessionDataValue(sessionData, storageKey) {
|
|
62
|
+
const value = sessionData?.[storageKey];
|
|
63
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
64
|
+
}
|
|
65
|
+
function clearValidatedSession() {
|
|
66
|
+
validatedAccessToken = '';
|
|
67
|
+
validatedUntilEpochMs = 0;
|
|
68
|
+
}
|
|
69
|
+
function clearFailedSessionFingerprint() {
|
|
70
|
+
failedSessionFingerprint = null;
|
|
71
|
+
}
|
|
72
|
+
function readSessionFingerprint(documentRef) {
|
|
73
|
+
return readStoredAccessToken(documentRef) || EMPTY_SESSION_FINGERPRINT;
|
|
74
|
+
}
|
|
75
|
+
function hasFailedSessionFingerprint(documentRef) {
|
|
76
|
+
return failedSessionFingerprint === readSessionFingerprint(documentRef);
|
|
77
|
+
}
|
|
78
|
+
function markFailedSessionFingerprint(documentRef) {
|
|
79
|
+
failedSessionFingerprint = readSessionFingerprint(documentRef);
|
|
80
|
+
}
|
|
81
|
+
function getTokenExpiryEpochMs(documentRef, accessToken) {
|
|
82
|
+
const windowRef = documentRef.defaultView;
|
|
83
|
+
const tokenParts = accessToken.split('.');
|
|
84
|
+
if (!windowRef?.atob || tokenParts.length !== JWT_PART_COUNT) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const normalizedPayload = tokenParts[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
88
|
+
const paddedPayload = normalizedPayload.padEnd(Math.ceil(normalizedPayload.length / 4) * 4, '=');
|
|
89
|
+
try {
|
|
90
|
+
const parsedPayload = JSON.parse(windowRef.atob(paddedPayload));
|
|
91
|
+
return typeof parsedPayload.exp === 'number' ? parsedPayload.exp * 1000 : null;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function markValidatedSession(documentRef) {
|
|
98
|
+
const accessToken = readStoredAccessToken(documentRef);
|
|
99
|
+
if (!accessToken) {
|
|
100
|
+
clearValidatedSession();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const tokenExpiryEpochMs = getTokenExpiryEpochMs(documentRef, accessToken);
|
|
104
|
+
if (!tokenExpiryEpochMs) {
|
|
105
|
+
clearValidatedSession();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
validatedAccessToken = accessToken;
|
|
109
|
+
validatedUntilEpochMs = tokenExpiryEpochMs;
|
|
110
|
+
}
|
|
111
|
+
function hasValidatedSession(documentRef) {
|
|
112
|
+
const accessToken = readStoredAccessToken(documentRef);
|
|
113
|
+
if (!accessToken) {
|
|
114
|
+
clearValidatedSession();
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (accessToken !== validatedAccessToken) {
|
|
118
|
+
markValidatedSession(documentRef);
|
|
119
|
+
}
|
|
120
|
+
if (!validatedAccessToken) {
|
|
121
|
+
clearValidatedSession();
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return validatedUntilEpochMs > Date.now() + TOKEN_EXPIRY_SKEW_MS;
|
|
125
|
+
}
|
|
126
|
+
function hasStoredSession(documentRef) {
|
|
127
|
+
return Boolean(readStoredAccessToken(documentRef));
|
|
128
|
+
}
|
|
129
|
+
function readStoredAccessToken(documentRef) {
|
|
130
|
+
return readSessionStorageValue(documentRef, 'access_token');
|
|
131
|
+
}
|
|
132
|
+
function readStoredSession(documentRef) {
|
|
133
|
+
const accessToken = readStoredAccessToken(documentRef);
|
|
134
|
+
if (!accessToken) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const userId = readSessionStorageValue(documentRef, 'user_id');
|
|
138
|
+
const role = readSessionStorageValue(documentRef, 'role');
|
|
139
|
+
return {
|
|
140
|
+
accessToken,
|
|
141
|
+
userId: userId || undefined,
|
|
142
|
+
role: role || undefined,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function persistSession(documentRef, sessionData) {
|
|
146
|
+
const sessionStorageRef = getSessionStorage(documentRef);
|
|
147
|
+
if (!sessionStorageRef) {
|
|
148
|
+
clearValidatedSession();
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
for (const storageKey of AUTH_SESSION_STORAGE_KEYS) {
|
|
152
|
+
const nextValue = readSessionDataValue(sessionData, storageKey);
|
|
153
|
+
if (nextValue) {
|
|
154
|
+
sessionStorageRef.setItem(storageKey, nextValue);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
sessionStorageRef.removeItem(storageKey);
|
|
158
|
+
}
|
|
159
|
+
markValidatedSession(documentRef);
|
|
160
|
+
clearFailedSessionFingerprint();
|
|
161
|
+
return readStoredSession(documentRef);
|
|
162
|
+
}
|
|
163
|
+
function clearStoredSession(documentRef, options) {
|
|
164
|
+
const sessionStorageRef = getSessionStorage(documentRef);
|
|
165
|
+
for (const storageKey of AUTH_SESSION_STORAGE_KEYS) {
|
|
166
|
+
sessionStorageRef?.removeItem(storageKey);
|
|
167
|
+
}
|
|
168
|
+
clearValidatedSession();
|
|
169
|
+
if (!options?.preserveFailedSessionFingerprint) {
|
|
170
|
+
clearFailedSessionFingerprint();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function validateStoredSession(documentRef, authService, options) {
|
|
174
|
+
if (!options?.forceRefresh && hasValidatedSession(documentRef)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
if (hasFailedSessionFingerprint(documentRef)) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
if (pendingSessionValidation) {
|
|
181
|
+
return pendingSessionValidation;
|
|
182
|
+
}
|
|
183
|
+
pendingSessionValidation = (async () => {
|
|
184
|
+
try {
|
|
185
|
+
const response = await firstValueFrom(authService.refreshAuthToken());
|
|
186
|
+
persistSession(documentRef, response.data);
|
|
187
|
+
return hasValidatedSession(documentRef);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
clearStoredSession(documentRef, { preserveFailedSessionFingerprint: true });
|
|
191
|
+
markFailedSessionFingerprint(documentRef);
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
pendingSessionValidation = null;
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
198
|
+
return pendingSessionValidation;
|
|
199
|
+
}
|
|
200
|
+
function injectSessionState() {
|
|
201
|
+
const documentRef = inject(DOCUMENT);
|
|
202
|
+
const authService = inject(AuthService);
|
|
203
|
+
return validateStoredSession(documentRef, authService);
|
|
204
|
+
}
|
|
205
|
+
function injectSessionRefresh() {
|
|
206
|
+
const documentRef = inject(DOCUMENT);
|
|
207
|
+
const authService = inject(AuthService);
|
|
208
|
+
return validateStoredSession(documentRef, authService, { forceRefresh: true });
|
|
209
|
+
}
|
|
210
|
+
function injectSessionClear() {
|
|
211
|
+
clearStoredSession(inject(DOCUMENT));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const PROTECTED_API_PATH_PREFIX = '/v1/';
|
|
215
|
+
const AUTH_PATH_PREFIX = '/v1/auth/';
|
|
216
|
+
const HEALTH_PATH = '/health';
|
|
217
|
+
const EDSIS_SKIP_AUTH = new HttpContextToken(() => false);
|
|
218
|
+
const EDSIS_AUTH_RETRY = new HttpContextToken(() => false);
|
|
219
|
+
function normalizeUrl(url) {
|
|
220
|
+
try {
|
|
221
|
+
return new URL(url);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function resolveApiPath(url, rootUrl) {
|
|
228
|
+
const normalizedUrl = normalizeUrl(url);
|
|
229
|
+
const normalizedRootUrl = normalizeUrl(rootUrl);
|
|
230
|
+
if (normalizedUrl && normalizedRootUrl) {
|
|
231
|
+
if (normalizedUrl.origin !== normalizedRootUrl.origin) {
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
if (!normalizedUrl.pathname.startsWith(normalizedRootUrl.pathname)) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const apiPath = normalizedUrl.pathname.slice(normalizedRootUrl.pathname.length) || '/';
|
|
238
|
+
return apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
|
|
239
|
+
}
|
|
240
|
+
if (url.startsWith(rootUrl)) {
|
|
241
|
+
const apiPath = url.slice(rootUrl.length).split(/[?#]/, 1)[0] ?? '/';
|
|
242
|
+
return apiPath.startsWith('/') ? apiPath : `/${apiPath}`;
|
|
243
|
+
}
|
|
244
|
+
if (url.startsWith('/')) {
|
|
245
|
+
return url.split(/[?#]/, 1)[0] ?? url;
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
function isAuthRequest(apiPath) {
|
|
250
|
+
return apiPath.startsWith(AUTH_PATH_PREFIX);
|
|
251
|
+
}
|
|
252
|
+
function isProtectedApiRequest(apiPath) {
|
|
253
|
+
return apiPath.startsWith(PROTECTED_API_PATH_PREFIX) && !isAuthRequest(apiPath);
|
|
254
|
+
}
|
|
255
|
+
function isHealthRequest(apiPath) {
|
|
256
|
+
return apiPath === HEALTH_PATH;
|
|
257
|
+
}
|
|
258
|
+
function isHandledRequest(apiPath) {
|
|
259
|
+
return isProtectedApiRequest(apiPath) || isAuthRequest(apiPath) || isHealthRequest(apiPath);
|
|
260
|
+
}
|
|
261
|
+
function applyCookieCredentials(request, apiPath) {
|
|
262
|
+
return isAuthRequest(apiPath) && !request.withCredentials ? request.clone({ withCredentials: true }) : request;
|
|
263
|
+
}
|
|
264
|
+
function applyBearerToken(request, accessToken, isRetry = false) {
|
|
265
|
+
return request.clone({
|
|
266
|
+
context: isRetry ? request.context.set(EDSIS_AUTH_RETRY, true) : request.context,
|
|
267
|
+
setHeaders: {
|
|
268
|
+
Authorization: `Bearer ${accessToken}`,
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
async function resolveAccessToken(documentRef, authService, options) {
|
|
273
|
+
const isSessionValid = await validateStoredSession(documentRef, authService, options);
|
|
274
|
+
return isSessionValid ? readStoredAccessToken(documentRef) : '';
|
|
275
|
+
}
|
|
276
|
+
function handleUnauthorizedError(error, request, next, documentRef, authService) {
|
|
277
|
+
if (!(error instanceof HttpErrorResponse) || error.status !== 401 || request.context.get(EDSIS_AUTH_RETRY)) {
|
|
278
|
+
return throwError(() => error);
|
|
279
|
+
}
|
|
280
|
+
return from(resolveAccessToken(documentRef, authService, { forceRefresh: true })).pipe(switchMap((refreshedAccessToken) => {
|
|
281
|
+
if (!refreshedAccessToken) {
|
|
282
|
+
clearStoredSession(documentRef);
|
|
283
|
+
return throwError(() => error);
|
|
284
|
+
}
|
|
285
|
+
return next(applyBearerToken(request, refreshedAccessToken, true));
|
|
286
|
+
}), catchError(() => {
|
|
287
|
+
clearStoredSession(documentRef);
|
|
288
|
+
return throwError(() => error);
|
|
289
|
+
}));
|
|
290
|
+
}
|
|
291
|
+
const edsisAuthInterceptor = (request, next) => {
|
|
292
|
+
const documentRef = inject(DOCUMENT);
|
|
293
|
+
const apiConfiguration = inject(ApiConfiguration);
|
|
294
|
+
const authService = inject(AuthService);
|
|
295
|
+
if (request.context.get(EDSIS_SKIP_AUTH)) {
|
|
296
|
+
return next(request);
|
|
297
|
+
}
|
|
298
|
+
const apiPath = resolveApiPath(request.url, apiConfiguration.rootUrl);
|
|
299
|
+
if (!apiPath || !isHandledRequest(apiPath)) {
|
|
300
|
+
return next(request);
|
|
301
|
+
}
|
|
302
|
+
const preparedRequest = applyCookieCredentials(request, apiPath);
|
|
303
|
+
if (isAuthRequest(apiPath) || isHealthRequest(apiPath)) {
|
|
304
|
+
return next(preparedRequest);
|
|
305
|
+
}
|
|
306
|
+
return from(resolveAccessToken(documentRef, authService)).pipe(switchMap((accessToken) => {
|
|
307
|
+
const authorizedRequest = accessToken ? applyBearerToken(preparedRequest, accessToken) : preparedRequest;
|
|
308
|
+
return next(authorizedRequest).pipe(catchError((error) => handleUnauthorizedError(error, preparedRequest, next, documentRef, authService)));
|
|
309
|
+
}));
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
function provideEdsisAuth(config) {
|
|
313
|
+
const resolvedConfig = resolveEdsisAuthConfig(config);
|
|
314
|
+
return makeEnvironmentProviders([
|
|
315
|
+
provideApiConfiguration(resolvedConfig.apiUrl),
|
|
316
|
+
provideHttpClient(withFetch(), withInterceptors([edsisAuthInterceptor])),
|
|
317
|
+
{
|
|
318
|
+
provide: EDSIS_AUTH_CONFIG,
|
|
319
|
+
useValue: resolvedConfig,
|
|
320
|
+
},
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const authenticatedGuard = async () => {
|
|
325
|
+
const router = inject(Router);
|
|
326
|
+
const authConfig = inject(EDSIS_AUTH_CONFIG);
|
|
327
|
+
if (await injectSessionState()) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
return router.parseUrl(authConfig.guestHomePath);
|
|
331
|
+
};
|
|
332
|
+
const homeRedirectGuard = async () => {
|
|
333
|
+
const router = inject(Router);
|
|
334
|
+
const authConfig = inject(EDSIS_AUTH_CONFIG);
|
|
335
|
+
return router.parseUrl((await injectSessionState()) ? authConfig.authenticatedHomePath : authConfig.guestHomePath);
|
|
336
|
+
};
|
|
337
|
+
const guestOnlyGuard = async () => {
|
|
338
|
+
const router = inject(Router);
|
|
339
|
+
const authConfig = inject(EDSIS_AUTH_CONFIG);
|
|
340
|
+
if (!(await injectSessionState())) {
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
return router.parseUrl(authConfig.authenticatedHomePath);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
class AuthShellPage {
|
|
347
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthShellPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
348
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.10", type: AuthShellPage, isStandalone: true, selector: "edsis-auth-shell-page", host: { classAttribute: "block min-h-screen bg-background text-foreground" }, ngImport: i0, template: `
|
|
349
|
+
<section
|
|
350
|
+
class="relative isolate flex min-h-screen items-center justify-center overflow-hidden px-4 py-10 sm:px-6 lg:px-8">
|
|
351
|
+
<div
|
|
352
|
+
aria-hidden="true"
|
|
353
|
+
class="absolute inset-0 bg-[radial-gradient(circle_at_top_left,rgba(14,165,233,0.14),transparent_34%),radial-gradient(circle_at_bottom_right,rgba(34,197,94,0.12),transparent_32%)]"></div>
|
|
354
|
+
|
|
355
|
+
<div
|
|
356
|
+
aria-hidden="true"
|
|
357
|
+
class="absolute inset-0 bg-[linear-gradient(rgba(148,163,184,0.08)_1px,transparent_1px),linear-gradient(90deg,rgba(148,163,184,0.08)_1px,transparent_1px)] bg-[size:4.5rem_4.5rem] [mask-image:radial-gradient(circle_at_center,black,transparent_82%)]"></div>
|
|
358
|
+
|
|
359
|
+
<div class="relative flex w-full max-w-xl justify-center">
|
|
360
|
+
<div aria-hidden="true" class="pointer-events-none absolute inset-0 z-20">
|
|
361
|
+
<div class="absolute left-1/2 top-0 w-screen -translate-x-1/2 border-t border-border/70"></div>
|
|
362
|
+
<div class="absolute left-1/2 bottom-0 w-screen -translate-x-1/2 border-t border-border/70"></div>
|
|
363
|
+
<div class="absolute left-0 top-1/2 h-screen -translate-y-1/2 border-l border-border/70"></div>
|
|
364
|
+
<div class="absolute right-0 top-1/2 h-screen -translate-y-1/2 border-l border-border/70"></div>
|
|
365
|
+
|
|
366
|
+
<div class="absolute left-0 top-0 h-8 w-8 -translate-x-1/2 -translate-y-1/2">
|
|
367
|
+
<div
|
|
368
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
369
|
+
<div
|
|
370
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
371
|
+
</div>
|
|
372
|
+
<div class="absolute right-0 top-0 h-8 w-8 translate-x-1/2 -translate-y-1/2">
|
|
373
|
+
<div
|
|
374
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
375
|
+
<div
|
|
376
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
377
|
+
</div>
|
|
378
|
+
<div class="absolute left-0 bottom-0 h-8 w-8 -translate-x-1/2 translate-y-1/2">
|
|
379
|
+
<div
|
|
380
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
381
|
+
<div
|
|
382
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
383
|
+
</div>
|
|
384
|
+
<div class="absolute right-0 bottom-0 h-8 w-8 translate-x-1/2 translate-y-1/2">
|
|
385
|
+
<div
|
|
386
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
387
|
+
<div
|
|
388
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
|
|
392
|
+
<div class="relative z-10 w-full border border-border/80 bg-card/95 p-6 shadow-2xl backdrop-blur sm:p-8">
|
|
393
|
+
<router-outlet />
|
|
394
|
+
</div>
|
|
395
|
+
</div>
|
|
396
|
+
</section>
|
|
397
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name", "routerOutletData"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
398
|
+
}
|
|
399
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthShellPage, decorators: [{
|
|
400
|
+
type: Component,
|
|
401
|
+
args: [{
|
|
402
|
+
selector: 'edsis-auth-shell-page',
|
|
403
|
+
imports: [RouterOutlet],
|
|
404
|
+
host: {
|
|
405
|
+
class: 'block min-h-screen bg-background text-foreground',
|
|
406
|
+
},
|
|
407
|
+
template: `
|
|
408
|
+
<section
|
|
409
|
+
class="relative isolate flex min-h-screen items-center justify-center overflow-hidden px-4 py-10 sm:px-6 lg:px-8">
|
|
410
|
+
<div
|
|
411
|
+
aria-hidden="true"
|
|
412
|
+
class="absolute inset-0 bg-[radial-gradient(circle_at_top_left,rgba(14,165,233,0.14),transparent_34%),radial-gradient(circle_at_bottom_right,rgba(34,197,94,0.12),transparent_32%)]"></div>
|
|
413
|
+
|
|
414
|
+
<div
|
|
415
|
+
aria-hidden="true"
|
|
416
|
+
class="absolute inset-0 bg-[linear-gradient(rgba(148,163,184,0.08)_1px,transparent_1px),linear-gradient(90deg,rgba(148,163,184,0.08)_1px,transparent_1px)] bg-[size:4.5rem_4.5rem] [mask-image:radial-gradient(circle_at_center,black,transparent_82%)]"></div>
|
|
417
|
+
|
|
418
|
+
<div class="relative flex w-full max-w-xl justify-center">
|
|
419
|
+
<div aria-hidden="true" class="pointer-events-none absolute inset-0 z-20">
|
|
420
|
+
<div class="absolute left-1/2 top-0 w-screen -translate-x-1/2 border-t border-border/70"></div>
|
|
421
|
+
<div class="absolute left-1/2 bottom-0 w-screen -translate-x-1/2 border-t border-border/70"></div>
|
|
422
|
+
<div class="absolute left-0 top-1/2 h-screen -translate-y-1/2 border-l border-border/70"></div>
|
|
423
|
+
<div class="absolute right-0 top-1/2 h-screen -translate-y-1/2 border-l border-border/70"></div>
|
|
424
|
+
|
|
425
|
+
<div class="absolute left-0 top-0 h-8 w-8 -translate-x-1/2 -translate-y-1/2">
|
|
426
|
+
<div
|
|
427
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
428
|
+
<div
|
|
429
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
430
|
+
</div>
|
|
431
|
+
<div class="absolute right-0 top-0 h-8 w-8 translate-x-1/2 -translate-y-1/2">
|
|
432
|
+
<div
|
|
433
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
434
|
+
<div
|
|
435
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
436
|
+
</div>
|
|
437
|
+
<div class="absolute left-0 bottom-0 h-8 w-8 -translate-x-1/2 translate-y-1/2">
|
|
438
|
+
<div
|
|
439
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
440
|
+
<div
|
|
441
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
442
|
+
</div>
|
|
443
|
+
<div class="absolute right-0 bottom-0 h-8 w-8 translate-x-1/2 translate-y-1/2">
|
|
444
|
+
<div
|
|
445
|
+
class="absolute left-1/2 top-1/2 h-5 -translate-x-1/2 -translate-y-1/2 border-l-2 border-primary"></div>
|
|
446
|
+
<div
|
|
447
|
+
class="absolute left-1/2 top-1/2 w-5 -translate-x-1/2 -translate-y-1/2 border-t-2 border-primary"></div>
|
|
448
|
+
</div>
|
|
449
|
+
</div>
|
|
450
|
+
|
|
451
|
+
<div class="relative z-10 w-full border border-border/80 bg-card/95 p-6 shadow-2xl backdrop-blur sm:p-8">
|
|
452
|
+
<router-outlet />
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
</section>
|
|
456
|
+
`,
|
|
457
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
458
|
+
}]
|
|
459
|
+
}] });
|
|
460
|
+
|
|
461
|
+
function buildVerifyUrl(config) {
|
|
462
|
+
const baseUrl = typeof window !== 'undefined' && window.location.origin ? window.location.origin : config.appUrl;
|
|
463
|
+
return new URL(config.verifyPath, `${baseUrl}/`).toString();
|
|
464
|
+
}
|
|
465
|
+
function extractMagicToken(queryToken, fragment) {
|
|
466
|
+
const tokenFromQuery = normalizeText(queryToken);
|
|
467
|
+
if (tokenFromQuery) {
|
|
468
|
+
return tokenFromQuery;
|
|
469
|
+
}
|
|
470
|
+
const normalizedFragment = normalizeText(fragment?.startsWith('#') ? fragment.slice(1) : fragment);
|
|
471
|
+
if (!normalizedFragment) {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
const fragmentParams = new URLSearchParams(normalizedFragment);
|
|
475
|
+
const tokenFromFragment = normalizeText(fragmentParams.get('token')) ??
|
|
476
|
+
normalizeText(fragmentParams.get('magic_token')) ??
|
|
477
|
+
normalizeText(fragmentParams.get('value'));
|
|
478
|
+
if (tokenFromFragment) {
|
|
479
|
+
return tokenFromFragment;
|
|
480
|
+
}
|
|
481
|
+
return normalizedFragment.includes('=') ? null : normalizedFragment;
|
|
482
|
+
}
|
|
483
|
+
function getResponseMessage(response, fallback) {
|
|
484
|
+
if (!hasMessage(response)) {
|
|
485
|
+
return fallback;
|
|
486
|
+
}
|
|
487
|
+
return normalizeText(response.message) ?? fallback;
|
|
488
|
+
}
|
|
489
|
+
function getErrorMessage(error, fallback) {
|
|
490
|
+
if (error instanceof HttpErrorResponse) {
|
|
491
|
+
const errorBody = error.error;
|
|
492
|
+
if (typeof errorBody === 'string') {
|
|
493
|
+
return normalizeText(errorBody) ?? fallback;
|
|
494
|
+
}
|
|
495
|
+
if (hasMessage(errorBody)) {
|
|
496
|
+
return normalizeText(errorBody.message) ?? fallback;
|
|
497
|
+
}
|
|
498
|
+
return normalizeText(error.message) ?? fallback;
|
|
499
|
+
}
|
|
500
|
+
if (error instanceof Error) {
|
|
501
|
+
return normalizeText(error.message) ?? fallback;
|
|
502
|
+
}
|
|
503
|
+
return fallback;
|
|
504
|
+
}
|
|
505
|
+
function hasMessage(value) {
|
|
506
|
+
return typeof value === 'object' && value !== null && 'message' in value;
|
|
507
|
+
}
|
|
508
|
+
function normalizeText(value) {
|
|
509
|
+
if (typeof value !== 'string') {
|
|
510
|
+
return null;
|
|
511
|
+
}
|
|
512
|
+
const normalizedValue = value.trim();
|
|
513
|
+
return normalizedValue.length > 0 ? normalizedValue : null;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
class AuthLoginPage {
|
|
517
|
+
destroyRef = inject(DestroyRef);
|
|
518
|
+
formBuilder = inject(FormBuilder);
|
|
519
|
+
authService = inject(AuthService);
|
|
520
|
+
authConfig = inject(EDSIS_AUTH_CONFIG);
|
|
521
|
+
form = this.formBuilder.nonNullable.group({
|
|
522
|
+
email: ['', [Validators.required, Validators.email, Validators.maxLength(255)]],
|
|
523
|
+
});
|
|
524
|
+
isSubmitting = signal(false, ...(ngDevMode ? [{ debugName: "isSubmitting" }] : /* istanbul ignore next */ []));
|
|
525
|
+
responseMessage = signal(null, ...(ngDevMode ? [{ debugName: "responseMessage" }] : /* istanbul ignore next */ []));
|
|
526
|
+
errorMessage = signal(null, ...(ngDevMode ? [{ debugName: "errorMessage" }] : /* istanbul ignore next */ []));
|
|
527
|
+
verifyUrl = buildVerifyUrl(this.authConfig);
|
|
528
|
+
emailControl = this.form.controls.email;
|
|
529
|
+
submit() {
|
|
530
|
+
if (this.form.invalid) {
|
|
531
|
+
this.form.markAllAsTouched();
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
this.isSubmitting.set(true);
|
|
535
|
+
this.responseMessage.set(null);
|
|
536
|
+
this.errorMessage.set(null);
|
|
537
|
+
const email = this.emailControl.getRawValue().trim().toLowerCase();
|
|
538
|
+
this.emailControl.setValue(email);
|
|
539
|
+
this.authService
|
|
540
|
+
.resendMagicLink({
|
|
541
|
+
body: {
|
|
542
|
+
email,
|
|
543
|
+
frontend_url: this.verifyUrl,
|
|
544
|
+
},
|
|
545
|
+
})
|
|
546
|
+
.pipe(takeUntilDestroyed(this.destroyRef), finalize(() => this.isSubmitting.set(false)))
|
|
547
|
+
.subscribe({
|
|
548
|
+
next: (response) => {
|
|
549
|
+
this.responseMessage.set(getResponseMessage(response, 'Magic link berhasil dikirim ulang.'));
|
|
550
|
+
},
|
|
551
|
+
error: (error) => {
|
|
552
|
+
this.errorMessage.set(getErrorMessage(error, 'Gagal mengirim magic link.'));
|
|
553
|
+
},
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthLoginPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
557
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.10", type: AuthLoginPage, isStandalone: true, selector: "edsis-auth-login-page", host: { classAttribute: "block" }, ngImport: i0, template: `
|
|
558
|
+
<div class="space-y-8">
|
|
559
|
+
<header class="space-y-3">
|
|
560
|
+
<p class="text-sm font-medium uppercase tracking-[0.24em] text-muted-foreground">Login</p>
|
|
561
|
+
<div class="space-y-2">
|
|
562
|
+
<h2 class="text-3xl font-semibold tracking-tight">Kirim ulang magic link untuk masuk.</h2>
|
|
563
|
+
<p class="max-w-xl text-sm leading-6 text-muted-foreground">
|
|
564
|
+
Masukkan email yang terdaftar. Modul auth akan memanggil endpoint resend dari SDK dan mengarahkan magic link
|
|
565
|
+
ke halaman verify.
|
|
566
|
+
</p>
|
|
567
|
+
</div>
|
|
568
|
+
</header>
|
|
569
|
+
|
|
570
|
+
<form class="space-y-5" [formGroup]="form" (ngSubmit)="submit()">
|
|
571
|
+
<div class="space-y-2">
|
|
572
|
+
<label class="text-sm font-medium" for="email">Email</label>
|
|
573
|
+
<input
|
|
574
|
+
id="email"
|
|
575
|
+
type="email"
|
|
576
|
+
inputmode="email"
|
|
577
|
+
autocomplete="email"
|
|
578
|
+
formControlName="email"
|
|
579
|
+
placeholder="nama@edsis.local"
|
|
580
|
+
class="w-full rounded-2xl border border-border bg-background px-4 py-3 text-sm text-foreground outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/15" />
|
|
581
|
+
|
|
582
|
+
@if (emailControl.invalid && (emailControl.dirty || emailControl.touched)) {
|
|
583
|
+
<p class="text-sm text-destructive">
|
|
584
|
+
@if (emailControl.hasError('required')) {
|
|
585
|
+
Email wajib diisi.
|
|
586
|
+
} @else {
|
|
587
|
+
Gunakan format email yang valid dengan panjang maksimal 255 karakter.
|
|
588
|
+
}
|
|
589
|
+
</p>
|
|
590
|
+
} @else {
|
|
591
|
+
<p class="text-sm text-muted-foreground">Link verifikasi akan diarahkan ke {{ verifyUrl }}.</p>
|
|
592
|
+
}
|
|
593
|
+
</div>
|
|
594
|
+
|
|
595
|
+
@if (responseMessage()) {
|
|
596
|
+
<div class="rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
|
597
|
+
{{ responseMessage() }}
|
|
598
|
+
</div>
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
@if (errorMessage()) {
|
|
602
|
+
<div class="rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
|
603
|
+
{{ errorMessage() }}
|
|
604
|
+
</div>
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
<button
|
|
608
|
+
type="submit"
|
|
609
|
+
[disabled]="form.invalid || isSubmitting()"
|
|
610
|
+
class="inline-flex w-full items-center justify-center rounded-2xl bg-primary px-4 py-3 text-sm font-semibold text-background transition hover:opacity-95 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-60">
|
|
611
|
+
{{ isSubmitting() ? 'Mengirim magic link...' : 'Kirim magic link' }}
|
|
612
|
+
</button>
|
|
613
|
+
</form>
|
|
614
|
+
</div>
|
|
615
|
+
`, isInline: true, dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],[formArray],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
616
|
+
}
|
|
617
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthLoginPage, decorators: [{
|
|
618
|
+
type: Component,
|
|
619
|
+
args: [{
|
|
620
|
+
selector: 'edsis-auth-login-page',
|
|
621
|
+
imports: [ReactiveFormsModule],
|
|
622
|
+
host: {
|
|
623
|
+
class: 'block',
|
|
624
|
+
},
|
|
625
|
+
template: `
|
|
626
|
+
<div class="space-y-8">
|
|
627
|
+
<header class="space-y-3">
|
|
628
|
+
<p class="text-sm font-medium uppercase tracking-[0.24em] text-muted-foreground">Login</p>
|
|
629
|
+
<div class="space-y-2">
|
|
630
|
+
<h2 class="text-3xl font-semibold tracking-tight">Kirim ulang magic link untuk masuk.</h2>
|
|
631
|
+
<p class="max-w-xl text-sm leading-6 text-muted-foreground">
|
|
632
|
+
Masukkan email yang terdaftar. Modul auth akan memanggil endpoint resend dari SDK dan mengarahkan magic link
|
|
633
|
+
ke halaman verify.
|
|
634
|
+
</p>
|
|
635
|
+
</div>
|
|
636
|
+
</header>
|
|
637
|
+
|
|
638
|
+
<form class="space-y-5" [formGroup]="form" (ngSubmit)="submit()">
|
|
639
|
+
<div class="space-y-2">
|
|
640
|
+
<label class="text-sm font-medium" for="email">Email</label>
|
|
641
|
+
<input
|
|
642
|
+
id="email"
|
|
643
|
+
type="email"
|
|
644
|
+
inputmode="email"
|
|
645
|
+
autocomplete="email"
|
|
646
|
+
formControlName="email"
|
|
647
|
+
placeholder="nama@edsis.local"
|
|
648
|
+
class="w-full rounded-2xl border border-border bg-background px-4 py-3 text-sm text-foreground outline-none transition focus:border-primary focus:ring-2 focus:ring-primary/15" />
|
|
649
|
+
|
|
650
|
+
@if (emailControl.invalid && (emailControl.dirty || emailControl.touched)) {
|
|
651
|
+
<p class="text-sm text-destructive">
|
|
652
|
+
@if (emailControl.hasError('required')) {
|
|
653
|
+
Email wajib diisi.
|
|
654
|
+
} @else {
|
|
655
|
+
Gunakan format email yang valid dengan panjang maksimal 255 karakter.
|
|
656
|
+
}
|
|
657
|
+
</p>
|
|
658
|
+
} @else {
|
|
659
|
+
<p class="text-sm text-muted-foreground">Link verifikasi akan diarahkan ke {{ verifyUrl }}.</p>
|
|
660
|
+
}
|
|
661
|
+
</div>
|
|
662
|
+
|
|
663
|
+
@if (responseMessage()) {
|
|
664
|
+
<div class="rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-800">
|
|
665
|
+
{{ responseMessage() }}
|
|
666
|
+
</div>
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
@if (errorMessage()) {
|
|
670
|
+
<div class="rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
|
671
|
+
{{ errorMessage() }}
|
|
672
|
+
</div>
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
<button
|
|
676
|
+
type="submit"
|
|
677
|
+
[disabled]="form.invalid || isSubmitting()"
|
|
678
|
+
class="inline-flex w-full items-center justify-center rounded-2xl bg-primary px-4 py-3 text-sm font-semibold text-background transition hover:opacity-95 focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-60">
|
|
679
|
+
{{ isSubmitting() ? 'Mengirim magic link...' : 'Kirim magic link' }}
|
|
680
|
+
</button>
|
|
681
|
+
</form>
|
|
682
|
+
</div>
|
|
683
|
+
`,
|
|
684
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
685
|
+
}]
|
|
686
|
+
}] });
|
|
687
|
+
|
|
688
|
+
class AuthLogoutPage {
|
|
689
|
+
destroyRef = inject(DestroyRef);
|
|
690
|
+
documentRef = inject(DOCUMENT);
|
|
691
|
+
router = inject(Router);
|
|
692
|
+
authService = inject(AuthService);
|
|
693
|
+
authConfig = inject(EDSIS_AUTH_CONFIG);
|
|
694
|
+
guestHomePath = this.authConfig.guestHomePath;
|
|
695
|
+
authenticatedHomePath = this.authConfig.authenticatedHomePath;
|
|
696
|
+
state = signal('pending', ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
697
|
+
message = signal('Mengakhiri sesi...', ...(ngDevMode ? [{ debugName: "message" }] : /* istanbul ignore next */ []));
|
|
698
|
+
ngOnInit() {
|
|
699
|
+
clearStoredSession(this.documentRef);
|
|
700
|
+
this.authService
|
|
701
|
+
.logoutAuthSession()
|
|
702
|
+
.pipe(takeUntilDestroyed(this.destroyRef), finalize(() => {
|
|
703
|
+
if (this.state() === 'pending') {
|
|
704
|
+
this.state.set('success');
|
|
705
|
+
}
|
|
706
|
+
}))
|
|
707
|
+
.subscribe({
|
|
708
|
+
next: (response) => {
|
|
709
|
+
this.state.set('success');
|
|
710
|
+
this.message.set(getResponseMessage(response, 'Sesi berhasil diakhiri.'));
|
|
711
|
+
void this.router.navigateByUrl(this.guestHomePath, { replaceUrl: true });
|
|
712
|
+
},
|
|
713
|
+
error: (error) => {
|
|
714
|
+
this.state.set('error');
|
|
715
|
+
this.message.set(getErrorMessage(error, 'Sesi lokal sudah dihapus, tetapi request logout gagal.'));
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthLogoutPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
720
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.10", type: AuthLogoutPage, isStandalone: true, selector: "edsis-auth-logout-page", host: { classAttribute: "block" }, ngImport: i0, template: `
|
|
721
|
+
<div class="space-y-6">
|
|
722
|
+
<header class="space-y-3">
|
|
723
|
+
<p class="text-sm font-medium uppercase tracking-[0.24em] text-muted-foreground">Logout</p>
|
|
724
|
+
<h2 class="text-3xl font-semibold tracking-tight">Mengakhiri sesi Edsis.</h2>
|
|
725
|
+
<p class="max-w-xl text-sm leading-6 text-muted-foreground">
|
|
726
|
+
Halaman ini membersihkan sesi lokal lalu memanggil endpoint logout untuk merevoke refresh-token cookie pada
|
|
727
|
+
backend.
|
|
728
|
+
</p>
|
|
729
|
+
</header>
|
|
730
|
+
|
|
731
|
+
<div class="rounded-2xl border border-border bg-background/80 px-5 py-4 text-sm leading-6 text-foreground">
|
|
732
|
+
{{ message() }}
|
|
733
|
+
</div>
|
|
734
|
+
|
|
735
|
+
@if (state() === 'error') {
|
|
736
|
+
<div class="rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
|
737
|
+
Backend tidak mengonfirmasi logout, tetapi sesi lokal sudah dihapus.
|
|
738
|
+
</div>
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
<div class="flex flex-wrap gap-3">
|
|
742
|
+
<a
|
|
743
|
+
[routerLink]="guestHomePath"
|
|
744
|
+
class="inline-flex items-center justify-center rounded-2xl bg-primary px-4 py-3 text-sm font-semibold text-background transition hover:opacity-95 focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
745
|
+
Kembali ke login
|
|
746
|
+
</a>
|
|
747
|
+
<a
|
|
748
|
+
[routerLink]="authenticatedHomePath"
|
|
749
|
+
class="inline-flex items-center justify-center rounded-2xl border border-border px-4 py-3 text-sm font-semibold text-foreground transition hover:bg-background focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
750
|
+
Buka dashboard
|
|
751
|
+
</a>
|
|
752
|
+
</div>
|
|
753
|
+
</div>
|
|
754
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
755
|
+
}
|
|
756
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthLogoutPage, decorators: [{
|
|
757
|
+
type: Component,
|
|
758
|
+
args: [{
|
|
759
|
+
selector: 'edsis-auth-logout-page',
|
|
760
|
+
imports: [RouterLink],
|
|
761
|
+
host: {
|
|
762
|
+
class: 'block',
|
|
763
|
+
},
|
|
764
|
+
template: `
|
|
765
|
+
<div class="space-y-6">
|
|
766
|
+
<header class="space-y-3">
|
|
767
|
+
<p class="text-sm font-medium uppercase tracking-[0.24em] text-muted-foreground">Logout</p>
|
|
768
|
+
<h2 class="text-3xl font-semibold tracking-tight">Mengakhiri sesi Edsis.</h2>
|
|
769
|
+
<p class="max-w-xl text-sm leading-6 text-muted-foreground">
|
|
770
|
+
Halaman ini membersihkan sesi lokal lalu memanggil endpoint logout untuk merevoke refresh-token cookie pada
|
|
771
|
+
backend.
|
|
772
|
+
</p>
|
|
773
|
+
</header>
|
|
774
|
+
|
|
775
|
+
<div class="rounded-2xl border border-border bg-background/80 px-5 py-4 text-sm leading-6 text-foreground">
|
|
776
|
+
{{ message() }}
|
|
777
|
+
</div>
|
|
778
|
+
|
|
779
|
+
@if (state() === 'error') {
|
|
780
|
+
<div class="rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
|
781
|
+
Backend tidak mengonfirmasi logout, tetapi sesi lokal sudah dihapus.
|
|
782
|
+
</div>
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
<div class="flex flex-wrap gap-3">
|
|
786
|
+
<a
|
|
787
|
+
[routerLink]="guestHomePath"
|
|
788
|
+
class="inline-flex items-center justify-center rounded-2xl bg-primary px-4 py-3 text-sm font-semibold text-background transition hover:opacity-95 focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
789
|
+
Kembali ke login
|
|
790
|
+
</a>
|
|
791
|
+
<a
|
|
792
|
+
[routerLink]="authenticatedHomePath"
|
|
793
|
+
class="inline-flex items-center justify-center rounded-2xl border border-border px-4 py-3 text-sm font-semibold text-foreground transition hover:bg-background focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
794
|
+
Buka dashboard
|
|
795
|
+
</a>
|
|
796
|
+
</div>
|
|
797
|
+
</div>
|
|
798
|
+
`,
|
|
799
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
800
|
+
}]
|
|
801
|
+
}] });
|
|
802
|
+
|
|
803
|
+
class AuthVerifyPage {
|
|
804
|
+
destroyRef = inject(DestroyRef);
|
|
805
|
+
documentRef = inject(DOCUMENT);
|
|
806
|
+
route = inject(ActivatedRoute);
|
|
807
|
+
router = inject(Router);
|
|
808
|
+
location = inject(Location);
|
|
809
|
+
authService = inject(AuthService);
|
|
810
|
+
authConfig = inject(EDSIS_AUTH_CONFIG);
|
|
811
|
+
guestHomePath = this.authConfig.guestHomePath;
|
|
812
|
+
authenticatedHomePath = this.authConfig.authenticatedHomePath;
|
|
813
|
+
state = signal('pending', ...(ngDevMode ? [{ debugName: "state" }] : /* istanbul ignore next */ []));
|
|
814
|
+
message = signal('Memverifikasi magic link...', ...(ngDevMode ? [{ debugName: "message" }] : /* istanbul ignore next */ []));
|
|
815
|
+
ngOnInit() {
|
|
816
|
+
combineLatest([this.route.queryParamMap, this.route.fragment])
|
|
817
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
818
|
+
.subscribe(([queryParamMap, fragment]) => {
|
|
819
|
+
const token = extractMagicToken(queryParamMap.get('token'), fragment);
|
|
820
|
+
this.clearTokenFromAddressBar();
|
|
821
|
+
if (!token) {
|
|
822
|
+
this.state.set('error');
|
|
823
|
+
this.message.set('Token magic link tidak ditemukan pada URL yang dibuka.');
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
this.verify(token);
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
clearTokenFromAddressBar() {
|
|
830
|
+
this.location.replaceState(this.authConfig.verifyPath);
|
|
831
|
+
}
|
|
832
|
+
verify(token) {
|
|
833
|
+
this.authService
|
|
834
|
+
.verifyMagicLink({
|
|
835
|
+
body: {
|
|
836
|
+
token,
|
|
837
|
+
device_type: 'web',
|
|
838
|
+
},
|
|
839
|
+
})
|
|
840
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
841
|
+
.subscribe({
|
|
842
|
+
next: (response) => {
|
|
843
|
+
const session = persistSession(this.documentRef, response.data);
|
|
844
|
+
if (!session) {
|
|
845
|
+
this.state.set('error');
|
|
846
|
+
this.message.set('Verifikasi berhasil, tetapi access token tidak ditemukan di respons backend.');
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
this.state.set('success');
|
|
850
|
+
this.message.set(getResponseMessage(response, 'Verifikasi berhasil. Mengarahkan ke dashboard...'));
|
|
851
|
+
void this.router.navigateByUrl(this.authenticatedHomePath, { replaceUrl: true });
|
|
852
|
+
},
|
|
853
|
+
error: (error) => {
|
|
854
|
+
this.state.set('error');
|
|
855
|
+
this.message.set(getErrorMessage(error, 'Magic link tidak valid atau sudah kedaluwarsa.'));
|
|
856
|
+
},
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthVerifyPage, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
860
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.10", type: AuthVerifyPage, isStandalone: true, selector: "edsis-auth-verify-page", host: { classAttribute: "block" }, ngImport: i0, template: `
|
|
861
|
+
<div class="space-y-6">
|
|
862
|
+
<header class="space-y-3">
|
|
863
|
+
<p class="text-sm font-medium uppercase tracking-[0.24em] text-muted-foreground">Verify</p>
|
|
864
|
+
<h2 class="text-3xl font-semibold tracking-tight">Memverifikasi magic link.</h2>
|
|
865
|
+
<p class="max-w-xl text-sm leading-6 text-muted-foreground">
|
|
866
|
+
Token akan dikonsumsi satu kali, sesi refresh cookie dibentuk di backend, lalu access token disimpan secara
|
|
867
|
+
lokal untuk aplikasi.
|
|
868
|
+
</p>
|
|
869
|
+
</header>
|
|
870
|
+
|
|
871
|
+
<div class="rounded-2xl border border-border bg-background/80 px-5 py-4 text-sm leading-6 text-foreground">
|
|
872
|
+
{{ message() }}
|
|
873
|
+
</div>
|
|
874
|
+
|
|
875
|
+
@if (state() === 'error') {
|
|
876
|
+
<div class="rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
|
877
|
+
Pastikan Anda membuka link terbaru dari email dan token belum pernah dipakai sebelumnya.
|
|
878
|
+
</div>
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
<div class="flex flex-wrap gap-3">
|
|
882
|
+
<a
|
|
883
|
+
[routerLink]="guestHomePath"
|
|
884
|
+
class="inline-flex items-center justify-center rounded-2xl border border-border px-4 py-3 text-sm font-semibold text-foreground transition hover:bg-background focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
885
|
+
Minta link baru
|
|
886
|
+
</a>
|
|
887
|
+
<a
|
|
888
|
+
[routerLink]="authenticatedHomePath"
|
|
889
|
+
class="inline-flex items-center justify-center rounded-2xl bg-primary px-4 py-3 text-sm font-semibold text-background transition hover:opacity-95 focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
890
|
+
Buka dashboard
|
|
891
|
+
</a>
|
|
892
|
+
</div>
|
|
893
|
+
</div>
|
|
894
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
895
|
+
}
|
|
896
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: AuthVerifyPage, decorators: [{
|
|
897
|
+
type: Component,
|
|
898
|
+
args: [{
|
|
899
|
+
selector: 'edsis-auth-verify-page',
|
|
900
|
+
imports: [RouterLink],
|
|
901
|
+
host: {
|
|
902
|
+
class: 'block',
|
|
903
|
+
},
|
|
904
|
+
template: `
|
|
905
|
+
<div class="space-y-6">
|
|
906
|
+
<header class="space-y-3">
|
|
907
|
+
<p class="text-sm font-medium uppercase tracking-[0.24em] text-muted-foreground">Verify</p>
|
|
908
|
+
<h2 class="text-3xl font-semibold tracking-tight">Memverifikasi magic link.</h2>
|
|
909
|
+
<p class="max-w-xl text-sm leading-6 text-muted-foreground">
|
|
910
|
+
Token akan dikonsumsi satu kali, sesi refresh cookie dibentuk di backend, lalu access token disimpan secara
|
|
911
|
+
lokal untuk aplikasi.
|
|
912
|
+
</p>
|
|
913
|
+
</header>
|
|
914
|
+
|
|
915
|
+
<div class="rounded-2xl border border-border bg-background/80 px-5 py-4 text-sm leading-6 text-foreground">
|
|
916
|
+
{{ message() }}
|
|
917
|
+
</div>
|
|
918
|
+
|
|
919
|
+
@if (state() === 'error') {
|
|
920
|
+
<div class="rounded-2xl border border-destructive/20 bg-destructive/10 px-4 py-3 text-sm text-destructive">
|
|
921
|
+
Pastikan Anda membuka link terbaru dari email dan token belum pernah dipakai sebelumnya.
|
|
922
|
+
</div>
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
<div class="flex flex-wrap gap-3">
|
|
926
|
+
<a
|
|
927
|
+
[routerLink]="guestHomePath"
|
|
928
|
+
class="inline-flex items-center justify-center rounded-2xl border border-border px-4 py-3 text-sm font-semibold text-foreground transition hover:bg-background focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
929
|
+
Minta link baru
|
|
930
|
+
</a>
|
|
931
|
+
<a
|
|
932
|
+
[routerLink]="authenticatedHomePath"
|
|
933
|
+
class="inline-flex items-center justify-center rounded-2xl bg-primary px-4 py-3 text-sm font-semibold text-background transition hover:opacity-95 focus:outline-none focus:ring-2 focus:ring-primary/20">
|
|
934
|
+
Buka dashboard
|
|
935
|
+
</a>
|
|
936
|
+
</div>
|
|
937
|
+
</div>
|
|
938
|
+
`,
|
|
939
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
940
|
+
}]
|
|
941
|
+
}] });
|
|
942
|
+
|
|
943
|
+
const authRoutes = [
|
|
944
|
+
{
|
|
945
|
+
path: '',
|
|
946
|
+
component: AuthShellPage,
|
|
947
|
+
children: [
|
|
948
|
+
{
|
|
949
|
+
path: 'login',
|
|
950
|
+
title: 'Login',
|
|
951
|
+
canActivate: [guestOnlyGuard],
|
|
952
|
+
component: AuthLoginPage,
|
|
953
|
+
},
|
|
954
|
+
{
|
|
955
|
+
path: 'logout',
|
|
956
|
+
title: 'Logout',
|
|
957
|
+
component: AuthLogoutPage,
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
path: 'verify',
|
|
961
|
+
title: 'Verify',
|
|
962
|
+
canActivate: [guestOnlyGuard],
|
|
963
|
+
component: AuthVerifyPage,
|
|
964
|
+
},
|
|
965
|
+
],
|
|
966
|
+
},
|
|
967
|
+
];
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Generated bundle index. Do not edit.
|
|
971
|
+
*/
|
|
972
|
+
|
|
973
|
+
export { AuthLoginPage, AuthLogoutPage, AuthShellPage, AuthVerifyPage, EDSIS_AUTH_CONFIG, EDSIS_SKIP_AUTH, authRoutes, authenticatedGuard, clearStoredSession, edsisAuthInterceptor, guestOnlyGuard, hasStoredSession, homeRedirectGuard, injectSessionClear, injectSessionRefresh, injectSessionState, persistSession, provideEdsisAuth, readStoredAccessToken, readStoredSession, resolveEdsisAuthConfig, validateStoredSession };
|
|
974
|
+
//# sourceMappingURL=edsis-angular-auth.mjs.map
|