@groundbrick/sveltekit-adapter 0.8.0 → 0.9.0
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 +213 -507
- package/dist/analytics/components/FacebookPixel.svelte +8 -27
- package/dist/analytics/components/GoogleAnalytics.svelte +12 -16
- package/dist/analytics/config/analytics.config.js +1 -1
- package/dist/analytics/config/analytics.config.js.map +1 -1
- package/dist/analytics/interfaces/IAnalyticsService.d.ts +5 -6
- package/dist/analytics/interfaces/IAnalyticsService.d.ts.map +1 -1
- package/dist/analytics/services/AnalyticsService.d.ts +2 -4
- package/dist/analytics/services/AnalyticsService.d.ts.map +1 -1
- package/dist/analytics/services/AnalyticsService.js +10 -9
- package/dist/analytics/services/AnalyticsService.js.map +1 -1
- package/dist/analytics/utils/consent.js +3 -3
- package/dist/analytics/utils/consent.js.map +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -5
- package/dist/auth/index.js.map +1 -1
- package/dist/client/ApiClient.d.ts.map +1 -1
- package/dist/client/ApiClient.js +4 -10
- package/dist/client/ApiClient.js.map +1 -1
- package/dist/client/apiWrapper.d.ts +31 -39
- package/dist/client/apiWrapper.d.ts.map +1 -1
- package/dist/client/apiWrapper.js +26 -27
- package/dist/client/apiWrapper.js.map +1 -1
- package/dist/client/authErrorHandler.js +1 -1
- package/dist/client/authErrorHandler.js.map +1 -1
- package/dist/client/hooks.d.ts +2 -2
- package/dist/client/hooks.js +2 -2
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/jwtDecoder.d.ts +8 -8
- package/dist/client/jwtDecoder.d.ts.map +1 -1
- package/dist/client/jwtDecoder.js +12 -15
- package/dist/client/jwtDecoder.js.map +1 -1
- package/dist/client/stores.d.ts.map +1 -1
- package/dist/client/stores.js +7 -16
- package/dist/client/stores.js.map +1 -1
- package/dist/consent/components/CookieConsent.svelte +3 -4
- package/dist/consent/config/consent.config.js +13 -13
- package/dist/consent/config/consent.config.js.map +1 -1
- package/dist/consent/index.js +1 -1
- package/dist/consent/index.js.map +1 -1
- package/dist/consent/services/ConsentService.d.ts.map +1 -1
- package/dist/consent/services/ConsentService.js +5 -11
- package/dist/consent/services/ConsentService.js.map +1 -1
- package/dist/consent/utils/analytics.js +2 -2
- package/dist/consent/utils/analytics.js.map +1 -1
- package/dist/cookies/index.d.ts +10 -23
- package/dist/cookies/index.d.ts.map +1 -1
- package/dist/cookies/index.js +9 -22
- package/dist/cookies/index.js.map +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +70 -65
- package/dist/hooks/index.js.map +1 -1
- package/dist/sentry/index.d.ts.map +1 -1
- package/dist/sentry/index.js +1 -1
- package/dist/sentry/index.js.map +1 -1
- package/dist/tracking/services/TrackingService.d.ts.map +1 -1
- package/dist/tracking/services/TrackingService.js +6 -7
- package/dist/tracking/services/TrackingService.js.map +1 -1
- package/dist/types/index.d.ts +19 -10
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -3
|
@@ -17,9 +17,7 @@ export interface ApiErrorResponse {
|
|
|
17
17
|
code?: string;
|
|
18
18
|
status?: number;
|
|
19
19
|
/**
|
|
20
|
-
* Structured payload the server attached to the error
|
|
21
|
-
* Carries what the UI needs to act on a code — an id to restore, a list of
|
|
22
|
-
* conflicts — instead of forcing it to parse the message.
|
|
20
|
+
* Structured payload the server attached to the error.
|
|
23
21
|
*/
|
|
24
22
|
details?: Record<string, unknown>;
|
|
25
23
|
};
|
|
@@ -47,7 +45,7 @@ export type ApiResponse<T = unknown> = ApiSuccessResponse<T> | ApiErrorResponse;
|
|
|
47
45
|
* showErrorNotification: false
|
|
48
46
|
* });
|
|
49
47
|
*
|
|
50
|
-
* // Login endpoint (skip auth error handling
|
|
48
|
+
* // Login endpoint (skip auth error handling)
|
|
51
49
|
* await apiWrapper.post('/api/auth/login', credentials, {
|
|
52
50
|
* skipAuthHandling: true,
|
|
53
51
|
* customErrorMessage: 'Invalid credentials. Please try again.'
|
|
@@ -59,11 +57,8 @@ export interface ApiWrapperOptions {
|
|
|
59
57
|
* Controls whether to show loading state in the apiStore
|
|
60
58
|
*
|
|
61
59
|
* When true (default), the apiStore loading state will be set to true
|
|
62
|
-
* during the API call and false when completed.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Set to false for background operations or when you want to handle
|
|
66
|
-
* loading states manually.
|
|
60
|
+
* during the API call and false when completed. When false, the store
|
|
61
|
+
* is left untouched.
|
|
67
62
|
*
|
|
68
63
|
* @default true
|
|
69
64
|
*
|
|
@@ -81,8 +76,8 @@ export interface ApiWrapperOptions {
|
|
|
81
76
|
* Controls whether to automatically show error notifications
|
|
82
77
|
*
|
|
83
78
|
* When true (default), errors will be displayed to the user via
|
|
84
|
-
* the notification system (toast messages).
|
|
85
|
-
*
|
|
79
|
+
* the notification system (toast messages). When false, no
|
|
80
|
+
* notification is shown.
|
|
86
81
|
*
|
|
87
82
|
* @default true
|
|
88
83
|
*
|
|
@@ -92,11 +87,9 @@ export interface ApiWrapperOptions {
|
|
|
92
87
|
* await apiWrapper.get('/api/users', { showErrorNotification: true });
|
|
93
88
|
*
|
|
94
89
|
* // Handle errors manually
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* // Custom error handling
|
|
99
|
-
* console.log('Custom error handling:', error);
|
|
90
|
+
* const result = await apiWrapper.get('/api/data', { showErrorNotification: false });
|
|
91
|
+
* if (!result.success) {
|
|
92
|
+
* console.log('Custom error handling:', result.error);
|
|
100
93
|
* }
|
|
101
94
|
* ```
|
|
102
95
|
*/
|
|
@@ -104,9 +97,8 @@ export interface ApiWrapperOptions {
|
|
|
104
97
|
/**
|
|
105
98
|
* Custom error message to display instead of the server-provided error
|
|
106
99
|
*
|
|
107
|
-
* When provided, this message
|
|
108
|
-
*
|
|
109
|
-
* error messages or localization.
|
|
100
|
+
* When provided, this message is shown in the notification. The returned
|
|
101
|
+
* error and the apiStore keep the server message.
|
|
110
102
|
*
|
|
111
103
|
* @example
|
|
112
104
|
* ```typescript
|
|
@@ -116,35 +108,34 @@ export interface ApiWrapperOptions {
|
|
|
116
108
|
* });
|
|
117
109
|
*
|
|
118
110
|
* // Localized error message
|
|
119
|
-
* await apiWrapper.post('/api/
|
|
120
|
-
* customErrorMessage: 'Não foi possível criar
|
|
111
|
+
* await apiWrapper.post('/api/orders', data, {
|
|
112
|
+
* customErrorMessage: 'Não foi possível criar a encomenda.'
|
|
121
113
|
* });
|
|
122
114
|
* ```
|
|
123
115
|
*/
|
|
124
116
|
customErrorMessage?: string;
|
|
125
117
|
/**
|
|
126
|
-
* Códigos
|
|
127
|
-
*
|
|
128
|
-
* a quem chamou; deixa é de ser registado como aviso no cliente.
|
|
118
|
+
* Códigos HTTP (ex.: `[404]`) que não são registados como aviso no cliente.
|
|
119
|
+
* O resultado chega na mesma como erro a quem chamou. Aplica-se a `get`.
|
|
129
120
|
*/
|
|
130
121
|
expectedStatuses?: number[];
|
|
131
122
|
/**
|
|
132
123
|
* Skip authentication error handling for login/logout endpoints
|
|
133
124
|
*
|
|
134
125
|
* When true, a 401 will not trigger automatic authentication
|
|
135
|
-
* error handling (like redirecting to login page).
|
|
136
|
-
*
|
|
126
|
+
* error handling (like redirecting to login page). The same applies to
|
|
127
|
+
* a 403 that is handled like an invalid session.
|
|
137
128
|
*
|
|
138
129
|
* @default false
|
|
139
130
|
*
|
|
140
131
|
* @example
|
|
141
132
|
* ```typescript
|
|
142
|
-
* // Login endpoint
|
|
133
|
+
* // Login endpoint
|
|
143
134
|
* await apiWrapper.post('/api/auth/login', credentials, {
|
|
144
135
|
* skipAuthHandling: true
|
|
145
136
|
* });
|
|
146
137
|
*
|
|
147
|
-
* // Logout endpoint
|
|
138
|
+
* // Logout endpoint
|
|
148
139
|
* await apiWrapper.post('/api/auth/logout', {}, {
|
|
149
140
|
* skipAuthHandling: true
|
|
150
141
|
* });
|
|
@@ -179,7 +170,7 @@ export declare class ApiWrapper {
|
|
|
179
170
|
*
|
|
180
171
|
* This is the core method that provides:
|
|
181
172
|
* - Automatic loading state management via apiStore
|
|
182
|
-
* - Authentication error handling (401
|
|
173
|
+
* - Authentication error handling (401 and session-invalid 403 codes log out and redirect; any other 403 only notifies)
|
|
183
174
|
* - Error notifications via toast system
|
|
184
175
|
* - Error state management in the store
|
|
185
176
|
*
|
|
@@ -191,7 +182,7 @@ export declare class ApiWrapper {
|
|
|
191
182
|
* @param options.customErrorMessage - Custom error message to display instead of server error
|
|
192
183
|
* @param options.skipAuthHandling - Skip the 401 logout/redirect for login/logout endpoints (default: false)
|
|
193
184
|
*
|
|
194
|
-
* @returns Promise that resolves to the API response or
|
|
185
|
+
* @returns Promise that resolves to the API response, or to an error response (`success: false`) on failure
|
|
195
186
|
*
|
|
196
187
|
* @example
|
|
197
188
|
* ```typescript
|
|
@@ -292,29 +283,31 @@ export declare class ApiWrapper {
|
|
|
292
283
|
/**
|
|
293
284
|
* Executes multiple API calls in parallel with shared error handling and loading state
|
|
294
285
|
*
|
|
295
|
-
* All API calls will be executed simultaneously using Promise.all()
|
|
296
|
-
*
|
|
297
|
-
*
|
|
286
|
+
* All API calls will be executed simultaneously using Promise.all(). If any call
|
|
287
|
+
* rejects or resolves to `success: false`, error handling is applied to it and
|
|
288
|
+
* an error response is returned.
|
|
298
289
|
*
|
|
299
290
|
* @template T - Tuple type representing the return types of all API calls
|
|
300
291
|
* @param apiCalls - Array of functions that return API call promises
|
|
301
292
|
* @param options - Optional configuration for error handling and loading state
|
|
302
|
-
* @returns Promise resolving to
|
|
293
|
+
* @returns Promise resolving to a response whose `data` holds the results, in order
|
|
303
294
|
*
|
|
304
295
|
* @example
|
|
305
296
|
* ```typescript
|
|
306
|
-
* const
|
|
297
|
+
* const response = await apiWrapper.parallel<[ApiResponse<User[]>, ApiResponse<Post[]>]>([
|
|
307
298
|
* () => apiClient.get('/api/users'),
|
|
308
|
-
* () => apiClient.get('/api/posts')
|
|
309
|
-
* () => apiClient.get('/api/comments')
|
|
299
|
+
* () => apiClient.get('/api/posts')
|
|
310
300
|
* ]);
|
|
301
|
+
* if (response.success) {
|
|
302
|
+
* const [users, posts] = response.data!;
|
|
303
|
+
* }
|
|
311
304
|
* ```
|
|
312
305
|
*
|
|
313
306
|
* @example
|
|
314
307
|
* ```typescript
|
|
315
308
|
* // With error handling options
|
|
316
309
|
* const results = await apiWrapper.parallel(
|
|
317
|
-
* [() =>
|
|
310
|
+
* [() => apiClient.get('/api/data1'), () => apiClient.get('/api/data2')],
|
|
318
311
|
* { customErrorMessage: 'Failed to load dashboard data' }
|
|
319
312
|
* );
|
|
320
313
|
* ```
|
|
@@ -324,7 +317,6 @@ export declare class ApiWrapper {
|
|
|
324
317
|
/**
|
|
325
318
|
* Factory function to create an ApiWrapper instance
|
|
326
319
|
*
|
|
327
|
-
* Provides a convenient way to create an ApiWrapper with the specified API client.
|
|
328
320
|
* The API client should implement standard HTTP methods (get, post, put, patch, delete)
|
|
329
321
|
* that return promises.
|
|
330
322
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiWrapper.d.ts","sourceRoot":"","sources":["../../src/client/apiWrapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apiWrapper.d.ts","sourceRoot":"","sources":["../../src/client/apiWrapper.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC3C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE;QACJ,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM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;IACG,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIrG;;;;;;;;;;;;;;;;;OAiBG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIpG;;;;;;;;;;;;;;;;OAgBG;IACG,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAItG;;;;;;;;;;;;;;OAcG;IACG,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAIvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,QAAQ,CAAC,CAAC,SAAS,GAAG,EAAE,EAC1B,QAAQ,EAAE,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAChC,OAAO,CAAC,EAAE,iBAAiB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAM7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,GAAG,GAAG,UAAU,CAE3D"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { apiStore } from './stores.js';
|
|
2
2
|
import { handleAuthError } from './authErrorHandler.js';
|
|
3
3
|
import { showError, showWarning } from './notifications.js';
|
|
4
|
-
// Error codes that
|
|
5
|
-
//
|
|
6
|
-
// authorization failure and must never log anyone out.
|
|
4
|
+
// Error codes that make a 403 be handled like an invalid session (logout and
|
|
5
|
+
// redirect). A 403 with any other code keeps the session.
|
|
7
6
|
const SESSION_INVALID_FORBIDDEN_CODES = ['PETSHOP_ACCESS_DENIED'];
|
|
8
7
|
function isSessionInvalidForbidden(error) {
|
|
9
8
|
return error?.status === 403 && SESSION_INVALID_FORBIDDEN_CODES.includes(error?.code);
|
|
10
9
|
}
|
|
11
|
-
//
|
|
10
|
+
// Timestamp of the last session-expired warning.
|
|
12
11
|
let lastSessionExpiredNoticeAt = 0;
|
|
13
12
|
/**
|
|
14
13
|
* Wraps API client calls with common error handling, loading states, and notifications
|
|
@@ -36,7 +35,7 @@ export class ApiWrapper {
|
|
|
36
35
|
*
|
|
37
36
|
* This is the core method that provides:
|
|
38
37
|
* - Automatic loading state management via apiStore
|
|
39
|
-
* - Authentication error handling (401
|
|
38
|
+
* - Authentication error handling (401 and session-invalid 403 codes log out and redirect; any other 403 only notifies)
|
|
40
39
|
* - Error notifications via toast system
|
|
41
40
|
* - Error state management in the store
|
|
42
41
|
*
|
|
@@ -48,7 +47,7 @@ export class ApiWrapper {
|
|
|
48
47
|
* @param options.customErrorMessage - Custom error message to display instead of server error
|
|
49
48
|
* @param options.skipAuthHandling - Skip the 401 logout/redirect for login/logout endpoints (default: false)
|
|
50
49
|
*
|
|
51
|
-
* @returns Promise that resolves to the API response or
|
|
50
|
+
* @returns Promise that resolves to the API response, or to an error response (`success: false`) on failure
|
|
52
51
|
*
|
|
53
52
|
* @example
|
|
54
53
|
* ```typescript
|
|
@@ -73,19 +72,15 @@ export class ApiWrapper {
|
|
|
73
72
|
if (result?.success)
|
|
74
73
|
return result;
|
|
75
74
|
else
|
|
76
|
-
throw result?.error;
|
|
75
|
+
throw result?.error ?? { message: result?.message };
|
|
77
76
|
}
|
|
78
|
-
catch (
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// shows the server message. The exception is a 403 whose code says the
|
|
83
|
-
// session itself does not belong here (wrong tenant), which is as good
|
|
84
|
-
// as not being logged in and still sends the user to login.
|
|
77
|
+
catch (caught) {
|
|
78
|
+
const error = caught ?? {};
|
|
79
|
+
// A 401, or a 403 with a session-invalid code, logs out and redirects
|
|
80
|
+
// to login. Any other error goes to the notification branch.
|
|
85
81
|
if (!skipAuthHandling && (error.status === 401 || isSessionInvalidForbidden(error))) {
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
// burst of parallel 401s doesn't stack identical toasts.
|
|
82
|
+
// Shows the session-expired warning before the redirect, at most
|
|
83
|
+
// once every 5 seconds.
|
|
89
84
|
if (error.status === 401 && this.isClientReady && Date.now() - lastSessionExpiredNoticeAt > 5000) {
|
|
90
85
|
lastSessionExpiredNoticeAt = Date.now();
|
|
91
86
|
showWarning('A sua sessão expirou. Por favor, inicie sessão novamente.');
|
|
@@ -216,41 +211,45 @@ export class ApiWrapper {
|
|
|
216
211
|
/**
|
|
217
212
|
* Executes multiple API calls in parallel with shared error handling and loading state
|
|
218
213
|
*
|
|
219
|
-
* All API calls will be executed simultaneously using Promise.all()
|
|
220
|
-
*
|
|
221
|
-
*
|
|
214
|
+
* All API calls will be executed simultaneously using Promise.all(). If any call
|
|
215
|
+
* rejects or resolves to `success: false`, error handling is applied to it and
|
|
216
|
+
* an error response is returned.
|
|
222
217
|
*
|
|
223
218
|
* @template T - Tuple type representing the return types of all API calls
|
|
224
219
|
* @param apiCalls - Array of functions that return API call promises
|
|
225
220
|
* @param options - Optional configuration for error handling and loading state
|
|
226
|
-
* @returns Promise resolving to
|
|
221
|
+
* @returns Promise resolving to a response whose `data` holds the results, in order
|
|
227
222
|
*
|
|
228
223
|
* @example
|
|
229
224
|
* ```typescript
|
|
230
|
-
* const
|
|
225
|
+
* const response = await apiWrapper.parallel<[ApiResponse<User[]>, ApiResponse<Post[]>]>([
|
|
231
226
|
* () => apiClient.get('/api/users'),
|
|
232
|
-
* () => apiClient.get('/api/posts')
|
|
233
|
-
* () => apiClient.get('/api/comments')
|
|
227
|
+
* () => apiClient.get('/api/posts')
|
|
234
228
|
* ]);
|
|
229
|
+
* if (response.success) {
|
|
230
|
+
* const [users, posts] = response.data!;
|
|
231
|
+
* }
|
|
235
232
|
* ```
|
|
236
233
|
*
|
|
237
234
|
* @example
|
|
238
235
|
* ```typescript
|
|
239
236
|
* // With error handling options
|
|
240
237
|
* const results = await apiWrapper.parallel(
|
|
241
|
-
* [() =>
|
|
238
|
+
* [() => apiClient.get('/api/data1'), () => apiClient.get('/api/data2')],
|
|
242
239
|
* { customErrorMessage: 'Failed to load dashboard data' }
|
|
243
240
|
* );
|
|
244
241
|
* ```
|
|
245
242
|
*/
|
|
246
243
|
async parallel(apiCalls, options) {
|
|
247
|
-
return this.call(() =>
|
|
244
|
+
return this.call(async () => {
|
|
245
|
+
const results = await Promise.all(apiCalls.map(fn => fn()));
|
|
246
|
+
return results.find(result => result?.success === false) ?? { success: true, data: results };
|
|
247
|
+
}, options);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
251
251
|
* Factory function to create an ApiWrapper instance
|
|
252
252
|
*
|
|
253
|
-
* Provides a convenient way to create an ApiWrapper with the specified API client.
|
|
254
253
|
* The API client should implement standard HTTP methods (get, post, put, patch, delete)
|
|
255
254
|
* that return promises.
|
|
256
255
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiWrapper.js","sourceRoot":"","sources":["../../src/client/apiWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D
|
|
1
|
+
{"version":3,"file":"apiWrapper.js","sourceRoot":"","sources":["../../src/client/apiWrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,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C,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,KAAK,CAAC,QAAQ,CACV,QAAgC,EAChC,OAA2B;QAE3B,OAAO,IAAI,CAAC,IAAI,CAAM,KAAK,IAAI,EAAE;YAC7B,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;YAC5D,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QACjG,CAAC,EAAE,OAAO,CAA4B,CAAC;IAC3C,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAc;IAC3C,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -22,7 +22,7 @@ export class AuthErrorHandler {
|
|
|
22
22
|
message: error.message,
|
|
23
23
|
});
|
|
24
24
|
authStore.logout();
|
|
25
|
-
// Redirect to login page
|
|
25
|
+
// Redirect to login page
|
|
26
26
|
const redirectTo = error.redirectTo || this.redirectPath;
|
|
27
27
|
logger.info('Redirecting to login page', { redirectTo });
|
|
28
28
|
// Add current page as return URL
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authErrorHandler.js","sourceRoot":"","sources":["../../src/client/authErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,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,CAAC,MAAM;YACpB,OAAO,EAAE,KAAK,CAAC,OAAO;SACzB,CAAC,CAAC;QAEH,SAAS,CAAC,MAAM,EAAE,CAAC;QAEnB,yBAAyB;QAEzB,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,YAAY,CAAC;QACzD,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAEzD,iCAAiC;QACjC,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC7C,MAAM,SAAS,GAAG,WAAW,KAAK,GAAG,IAAI,WAAW,KAAK,UAAU;YAC/D,CAAC,CAAC,cAAc,kBAAkB,CAAC,WAAW,CAAC,EAAE;YACjD,CAAC,CAAC,EAAE,CAAC;QAET,MAAM,IAAI,CAAC,GAAG,UAAU,GAAG,SAAS,EAAE,CAAC,CAAC;IAE5C,CAAC;CACJ;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAEvD,gCAAgC;AAChC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAgB,EAAE,EAAE,CAAC,gBAAgB,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/client/hooks.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare function useNavigationNotificationClear(): void;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Clears non-persistent notifications when called in the browser.
|
|
8
|
+
* Call it from a page or component.
|
|
9
9
|
*/
|
|
10
10
|
export declare function useClearNotificationsOnMount(): void;
|
|
11
11
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/client/hooks.js
CHANGED
|
@@ -17,8 +17,8 @@ export function useNavigationNotificationClear() {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Clears non-persistent notifications when called in the browser.
|
|
21
|
+
* Call it from a page or component.
|
|
22
22
|
*/
|
|
23
23
|
export function useClearNotificationsOnMount() {
|
|
24
24
|
if (browser) {
|
package/dist/client/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { ApiClient, createApiClient } from './ApiClient.js';
|
|
|
2
2
|
export { authStore, apiStore, currentUser, isLoading, currentError, initializeStores, initializeAuth, initializeFromJwt, initializeFromToken, clearErrors, } from './stores.js';
|
|
3
3
|
// Export JWT decoder utilities
|
|
4
4
|
export { decodeJwtToken, safeDecodeJwt, hasPermission, hasAnyPermission, hasAllPermissions, getUserDisplayName, getAdditionalFields } from './jwtDecoder.js';
|
|
5
|
-
// Export
|
|
5
|
+
// Export notification system
|
|
6
6
|
export { notificationStore, notifications, errorNotifications, successNotifications, warningNotifications, infoNotifications, latestError, latestSuccess, hasNotifications, hasErrors, hasSuccess, showSuccess, showError, showWarning, showInfo, clearAllNotifications, clearNotificationsByType, clearNonPersistentNotifications, removeNotification } from './notifications.js';
|
|
7
7
|
// Export navigation hooks
|
|
8
8
|
export { useNavigationNotificationClear, useClearNotificationsOnMount } from './hooks.js';
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,+BAA+B;AAC/B,OAAO,EACL,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,+BAA+B;AAC/B,OAAO,EACL,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EAGpB,MAAM,iBAAiB,CAAC;AAEzB,6BAA6B;AAC7B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,QAAQ,EACR,qBAAqB,EACrB,wBAAwB,EACxB,+BAA+B,EAC/B,kBAAkB,EACnB,MAAM,oBAAoB,CAAC;AAE5B,0BAA0B;AAC1B,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,4BAA4B;AAC5B,OAAO,EACL,gBAAgB,EAChB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,6BAA6B;AAC7B,OAAO,EACL,UAAU,EACV,gBAAgB,EAKjB,MAAM,iBAAiB,CAAC"}
|
|
@@ -16,21 +16,20 @@ export interface DecodedJwt {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Safely decode JWT token client-side without verification
|
|
19
|
-
* This only decodes the payload
|
|
19
|
+
* This only decodes the payload; the signature is not verified.
|
|
20
|
+
* Returns null when the token cannot be decoded.
|
|
20
21
|
*/
|
|
21
22
|
export declare function decodeJwtToken(token: string): DecodedJwt | null;
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
-
* In browser, this will return null as HTTP-only cookies are not accessible
|
|
24
|
+
* Always returns null, on the server and in the browser.
|
|
25
25
|
*/
|
|
26
26
|
export declare function getAuthTokenFromCookie(): string | null;
|
|
27
27
|
/**
|
|
28
28
|
* Check if user has specific permission based on role hierarchy
|
|
29
29
|
* - staff: check permissions array
|
|
30
|
-
* - admin: has all permissions
|
|
31
|
-
* - super_admin: has all permissions
|
|
32
|
-
* -
|
|
33
|
-
TODO: REMOVE ANY REFERENCE TO FIXED ROLES - MAKE IT GENERIC
|
|
30
|
+
* - admin: has all permissions
|
|
31
|
+
* - super_admin: has all permissions
|
|
32
|
+
* - any other role: has no permissions
|
|
34
33
|
*/
|
|
35
34
|
export declare function hasPermission(payload: JwtPayload, permission: string): boolean;
|
|
36
35
|
/**
|
|
@@ -50,7 +49,8 @@ export declare function getUserDisplayName(payload: JwtPayload): string;
|
|
|
50
49
|
*/
|
|
51
50
|
export declare function getAdditionalFields(payload: JwtPayload): Record<string, any>;
|
|
52
51
|
/**
|
|
53
|
-
*
|
|
52
|
+
* Decodes a JWT token. Returns null for an empty or undecodable token; an
|
|
53
|
+
* expired token is returned with `isExpired: true`.
|
|
54
54
|
*/
|
|
55
55
|
export declare function safeDecodeJwt(token: string | null | undefined): DecodedJwt | null;
|
|
56
56
|
//# sourceMappingURL=jwtDecoder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwtDecoder.d.ts","sourceRoot":"","sources":["../../src/client/jwtDecoder.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,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AAM,EAAE,GAAG,OAAO,CAErF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAE9D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAG5E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,IAAI,CAiBjF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { browser } from '$app/environment';
|
|
2
2
|
/**
|
|
3
3
|
* Safely decode JWT token client-side without verification
|
|
4
|
-
* This only decodes the payload
|
|
4
|
+
* This only decodes the payload; the signature is not verified.
|
|
5
|
+
* Returns null when the token cannot be decoded.
|
|
5
6
|
*/
|
|
6
7
|
export function decodeJwtToken(token) {
|
|
7
8
|
try {
|
|
@@ -34,39 +35,34 @@ export function decodeJwtToken(token) {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
37
|
-
*
|
|
38
|
-
* In browser, this will return null as HTTP-only cookies are not accessible
|
|
38
|
+
* Always returns null, on the server and in the browser.
|
|
39
39
|
*/
|
|
40
40
|
export function getAuthTokenFromCookie() {
|
|
41
41
|
if (!browser) {
|
|
42
|
-
// Server-side: would need to pass from server context
|
|
43
42
|
return null;
|
|
44
43
|
}
|
|
45
|
-
// Client-side: HTTP-only cookies are not accessible via document.cookie
|
|
46
|
-
// Token should be available through server-side rendering or API calls
|
|
47
44
|
return null;
|
|
48
45
|
}
|
|
49
46
|
/**
|
|
50
47
|
* Check if user has specific permission based on role hierarchy
|
|
51
48
|
* - staff: check permissions array
|
|
52
|
-
* - admin: has all permissions
|
|
53
|
-
* - super_admin: has all permissions
|
|
54
|
-
* -
|
|
55
|
-
TODO: REMOVE ANY REFERENCE TO FIXED ROLES - MAKE IT GENERIC
|
|
49
|
+
* - admin: has all permissions
|
|
50
|
+
* - super_admin: has all permissions
|
|
51
|
+
* - any other role: has no permissions
|
|
56
52
|
*/
|
|
57
53
|
export function hasPermission(payload, permission) {
|
|
58
54
|
if (!payload)
|
|
59
55
|
return false;
|
|
60
56
|
switch (payload.role) {
|
|
61
57
|
case 'super_admin':
|
|
62
|
-
return true;
|
|
58
|
+
return true;
|
|
63
59
|
case 'admin':
|
|
64
|
-
return true;
|
|
60
|
+
return true;
|
|
65
61
|
case 'staff':
|
|
66
62
|
return payload.permissions?.includes(permission) || false;
|
|
67
63
|
case 'customer':
|
|
68
64
|
default:
|
|
69
|
-
return false;
|
|
65
|
+
return false;
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
68
|
/**
|
|
@@ -95,7 +91,8 @@ export function getAdditionalFields(payload) {
|
|
|
95
91
|
return additionalFields;
|
|
96
92
|
}
|
|
97
93
|
/**
|
|
98
|
-
*
|
|
94
|
+
* Decodes a JWT token. Returns null for an empty or undecodable token; an
|
|
95
|
+
* expired token is returned with `isExpired: true`.
|
|
99
96
|
*/
|
|
100
97
|
export function safeDecodeJwt(token) {
|
|
101
98
|
if (!token || typeof token !== 'string') {
|
|
@@ -107,7 +104,7 @@ export function safeDecodeJwt(token) {
|
|
|
107
104
|
}
|
|
108
105
|
if (decoded.isExpired) {
|
|
109
106
|
console.debug('JWT token is expired');
|
|
110
|
-
return decoded;
|
|
107
|
+
return decoded;
|
|
111
108
|
}
|
|
112
109
|
return decoded;
|
|
113
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwtDecoder.js","sourceRoot":"","sources":["../../src/client/jwtDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAqB3C
|
|
1
|
+
{"version":3,"file":"jwtDecoder.js","sourceRoot":"","sources":["../../src/client/jwtDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAqB3C;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CAAC;IAC1F,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAgC;IAC1D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IAEtC,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../../src/client/stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEpF,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"stores.d.ts","sourceRoot":"","sources":["../../src/client/stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEpF,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AA8HjE,eAAO,MAAM,SAAS;WAvHX,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI;YACtC,MAAM,IAAI;gBACN,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI;cAC5B,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;gBAC5B,MAAM,IAAI;uBACH,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI;yBAC9B,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO;CAiHT,CAAC;AAoC3C,eAAO,MAAM,QAAQ;gBA7BL,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI;cAC5B,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;oBACxB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;CA2BZ,CAAC;AAQzC,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAGhE,CAAC;AAGF,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,OAAO,CAGvC,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,CAGhD,CAAC;AAOF,wBAAgB,gBAAgB,IAAI,IAAI,CAIvC;AAKD,wBAAgB,WAAW,IAAI,IAAI,CAGlC;AAGD,wBAAsB,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CA2BlE;AAGD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAE9D;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D"}
|
package/dist/client/stores.js
CHANGED
|
@@ -16,7 +16,6 @@ function createAuthStore() {
|
|
|
16
16
|
set,
|
|
17
17
|
update,
|
|
18
18
|
login: (user) => {
|
|
19
|
-
// HttpOnly cookies are handled by server - no client-side storage needed
|
|
20
19
|
set({
|
|
21
20
|
isAuthenticated: true,
|
|
22
21
|
user,
|
|
@@ -25,7 +24,6 @@ function createAuthStore() {
|
|
|
25
24
|
});
|
|
26
25
|
},
|
|
27
26
|
logout: () => {
|
|
28
|
-
// HttpOnly cookies are cleared by server via /auth/logout endpoint
|
|
29
27
|
set({
|
|
30
28
|
isAuthenticated: false,
|
|
31
29
|
user: null,
|
|
@@ -40,9 +38,7 @@ function createAuthStore() {
|
|
|
40
38
|
update(state => ({ ...state, error, loading: false }));
|
|
41
39
|
},
|
|
42
40
|
initialize: () => {
|
|
43
|
-
//
|
|
44
|
-
// The app layout will call initializeFromJwt() with decoded JWT data
|
|
45
|
-
// to avoid circular dependencies and API calls
|
|
41
|
+
// No-op
|
|
46
42
|
},
|
|
47
43
|
initializeFromJwt: (jwtPayload) => {
|
|
48
44
|
// Convert JWT payload to user object (generic fields only)
|
|
@@ -89,11 +85,6 @@ function createAuthStore() {
|
|
|
89
85
|
loading: false,
|
|
90
86
|
error: null
|
|
91
87
|
});
|
|
92
|
-
// console.debug('Auth initialized from token', {
|
|
93
|
-
// userId: decoded.payload.userId,
|
|
94
|
-
// role: decoded.payload.role,
|
|
95
|
-
// permissionsCount: decoded.payload.permissions?.length || 0
|
|
96
|
-
// });
|
|
97
88
|
return true;
|
|
98
89
|
}
|
|
99
90
|
catch (error) {
|
|
@@ -152,20 +143,20 @@ export function clearErrors() {
|
|
|
152
143
|
authStore.setError(null);
|
|
153
144
|
apiStore.setError(null);
|
|
154
145
|
}
|
|
155
|
-
// Initialize auth with API client (deprecated - use initializeFromJwt instead)
|
|
146
|
+
// Initialize auth with API client via GET /auth/me (deprecated - use initializeFromJwt instead)
|
|
156
147
|
export async function initializeAuth(apiClient) {
|
|
157
148
|
if (!browser)
|
|
158
149
|
return;
|
|
159
|
-
// Get current auth state
|
|
150
|
+
// Get current auth state
|
|
160
151
|
const currentState = get(authStore);
|
|
161
|
-
// If user is already authenticated, skip the API call
|
|
152
|
+
// If user is already authenticated, skip the API call
|
|
162
153
|
if (currentState.isAuthenticated && currentState.user) {
|
|
163
154
|
console.debug('Auth already initialized, skipping API call');
|
|
164
155
|
return;
|
|
165
156
|
}
|
|
166
157
|
authStore.setLoading(true);
|
|
167
158
|
try {
|
|
168
|
-
//
|
|
159
|
+
// Authenticated by the HttpOnly cookie
|
|
169
160
|
const result = await apiClient.get('/auth/me');
|
|
170
161
|
if (result) {
|
|
171
162
|
authStore.login(result);
|
|
@@ -175,12 +166,12 @@ export async function initializeAuth(apiClient) {
|
|
|
175
166
|
}
|
|
176
167
|
}
|
|
177
168
|
catch (error) {
|
|
178
|
-
// User not authenticated or network error
|
|
169
|
+
// User not authenticated or network error
|
|
179
170
|
console.debug('Auth initialization: user not authenticated');
|
|
180
171
|
authStore.setLoading(false);
|
|
181
172
|
}
|
|
182
173
|
}
|
|
183
|
-
// Initialize auth from JWT payload
|
|
174
|
+
// Initialize auth from JWT payload
|
|
184
175
|
export function initializeFromJwt(jwtPayload) {
|
|
185
176
|
authStore.initializeFromJwt(jwtPayload);
|
|
186
177
|
}
|