@willphan1712000/frontend 1.2.0 → 1.4.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/dist/index.d.mts +164 -1
- package/dist/index.d.ts +164 -1
- package/dist/index.js +129 -1
- package/dist/index.mjs +113 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -375,4 +375,167 @@ declare class Transform {
|
|
|
375
375
|
private transform;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
interface HandleAsyncType<DataType> {
|
|
379
|
+
error?: string;
|
|
380
|
+
data?: DataType;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* HandleAsync function -> automatically handle try catch implementation from a promise
|
|
384
|
+
* @param data a promise that returns a data value
|
|
385
|
+
* @returns Promise<{error?, data?}>
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
*
|
|
389
|
+
* const { error, data } = await handleAsync(api('/api/call')) // api is a function that calls an api and returns a promise with possible errors thrown in between
|
|
390
|
+
*/
|
|
391
|
+
declare function handleAsync<DataType>(data: Promise<DataType>): Promise<HandleAsyncType<DataType>>;
|
|
392
|
+
|
|
393
|
+
declare const tools: {
|
|
394
|
+
handleAsync: typeof handleAsync;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* This interface provides a comprehensive guides on how to design auth object used for authentication on client side
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
*
|
|
402
|
+
* class auth implements AuthInterface {
|
|
403
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
404
|
+
redirect?: string;
|
|
405
|
+
client_id?: string;
|
|
406
|
+
callback_api?: string;
|
|
407
|
+
}): string {
|
|
408
|
+
...
|
|
409
|
+
}
|
|
410
|
+
signin({ username, email, password, redirect, }: {
|
|
411
|
+
username: string;
|
|
412
|
+
email?: string;
|
|
413
|
+
password: string;
|
|
414
|
+
redirect?: string;
|
|
415
|
+
}): Promise<void> {
|
|
416
|
+
...
|
|
417
|
+
}
|
|
418
|
+
validate({ state }: { state?: string; }): Promise<any> {
|
|
419
|
+
...
|
|
420
|
+
}
|
|
421
|
+
signout({ state }: { state?: string; }): Promise<void> {
|
|
422
|
+
...
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
*/
|
|
427
|
+
interface AuthInterface<User = any> {
|
|
428
|
+
/**
|
|
429
|
+
*
|
|
430
|
+
* @param redirect: route that will be returned after successful authentication
|
|
431
|
+
* @param client_id: oauth client id
|
|
432
|
+
* @param callback_api: api route for callback
|
|
433
|
+
* @returns sign in url
|
|
434
|
+
*/
|
|
435
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
436
|
+
redirect?: string;
|
|
437
|
+
client_id?: string;
|
|
438
|
+
callback_api?: string;
|
|
439
|
+
}): string;
|
|
440
|
+
/**
|
|
441
|
+
* Authenticate a user
|
|
442
|
+
*/
|
|
443
|
+
signin({ username, email, password, redirect, }: {
|
|
444
|
+
username: string;
|
|
445
|
+
email?: string;
|
|
446
|
+
password: string;
|
|
447
|
+
redirect?: string;
|
|
448
|
+
}): Promise<void>;
|
|
449
|
+
/**
|
|
450
|
+
* Validate user authentication
|
|
451
|
+
*/
|
|
452
|
+
validate({ state }: {
|
|
453
|
+
state?: string;
|
|
454
|
+
}): Promise<User>;
|
|
455
|
+
/**
|
|
456
|
+
* Sign a user out
|
|
457
|
+
*/
|
|
458
|
+
signout({ state }: {
|
|
459
|
+
state?: string;
|
|
460
|
+
}): Promise<void>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
type SessionType = {
|
|
464
|
+
username?: string;
|
|
465
|
+
email?: string;
|
|
466
|
+
role?: string;
|
|
467
|
+
} | undefined;
|
|
468
|
+
type SessionContextType = {
|
|
469
|
+
isLoading: boolean;
|
|
470
|
+
session: SessionType;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* This interface provides a guide to design storage object used for client side to operate storage operations
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
*
|
|
478
|
+
* class storage implements StorageInterface {
|
|
479
|
+
getToken(): string | null {
|
|
480
|
+
...
|
|
481
|
+
}
|
|
482
|
+
getUser(): SessionType | null {
|
|
483
|
+
...
|
|
484
|
+
}
|
|
485
|
+
setToken({ token }: { token: string; }): void {
|
|
486
|
+
...
|
|
487
|
+
}
|
|
488
|
+
removeToken(): void {
|
|
489
|
+
...
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
*/
|
|
493
|
+
interface StorageInterface {
|
|
494
|
+
getToken(): string | null;
|
|
495
|
+
getUser(): SessionType | null;
|
|
496
|
+
setToken({ token }: {
|
|
497
|
+
token: string;
|
|
498
|
+
}): void;
|
|
499
|
+
removeToken(): void;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Will-Auth - retrieve session
|
|
504
|
+
* @returns session context
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
*
|
|
508
|
+
* const { isLoading, session } = useSession()
|
|
509
|
+
*/
|
|
510
|
+
declare function useSession(): SessionContextType;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Custom Session Provider using React Context
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
*
|
|
517
|
+
* <SessionProvider value={useAuthClient(auth)}>
|
|
518
|
+
* ...
|
|
519
|
+
* </SessionProvider>
|
|
520
|
+
* // auth object implementing AuthInterface
|
|
521
|
+
*/
|
|
522
|
+
declare const SessionProvider: ({ value, children, }: {
|
|
523
|
+
value: SessionContextType;
|
|
524
|
+
children: ReactNode;
|
|
525
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Custom hook for auth
|
|
529
|
+
* - Copyright: Will Phan
|
|
530
|
+
* @param auth Auth object implementing AuthInterface
|
|
531
|
+
* @returns SessionContextType
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
*
|
|
535
|
+
* const authClient = new auth() // auth class implements AuthInterface
|
|
536
|
+
* const { isLoading, session } = useAuthClient(authClient) // auth is an auth object
|
|
537
|
+
*
|
|
538
|
+
*/
|
|
539
|
+
declare const useAuthClient: (auth: AuthInterface<SessionType>) => SessionContextType;
|
|
540
|
+
|
|
541
|
+
export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession };
|
package/dist/index.d.ts
CHANGED
|
@@ -375,4 +375,167 @@ declare class Transform {
|
|
|
375
375
|
private transform;
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
interface HandleAsyncType<DataType> {
|
|
379
|
+
error?: string;
|
|
380
|
+
data?: DataType;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* HandleAsync function -> automatically handle try catch implementation from a promise
|
|
384
|
+
* @param data a promise that returns a data value
|
|
385
|
+
* @returns Promise<{error?, data?}>
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
*
|
|
389
|
+
* const { error, data } = await handleAsync(api('/api/call')) // api is a function that calls an api and returns a promise with possible errors thrown in between
|
|
390
|
+
*/
|
|
391
|
+
declare function handleAsync<DataType>(data: Promise<DataType>): Promise<HandleAsyncType<DataType>>;
|
|
392
|
+
|
|
393
|
+
declare const tools: {
|
|
394
|
+
handleAsync: typeof handleAsync;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* This interface provides a comprehensive guides on how to design auth object used for authentication on client side
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
*
|
|
402
|
+
* class auth implements AuthInterface {
|
|
403
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
404
|
+
redirect?: string;
|
|
405
|
+
client_id?: string;
|
|
406
|
+
callback_api?: string;
|
|
407
|
+
}): string {
|
|
408
|
+
...
|
|
409
|
+
}
|
|
410
|
+
signin({ username, email, password, redirect, }: {
|
|
411
|
+
username: string;
|
|
412
|
+
email?: string;
|
|
413
|
+
password: string;
|
|
414
|
+
redirect?: string;
|
|
415
|
+
}): Promise<void> {
|
|
416
|
+
...
|
|
417
|
+
}
|
|
418
|
+
validate({ state }: { state?: string; }): Promise<any> {
|
|
419
|
+
...
|
|
420
|
+
}
|
|
421
|
+
signout({ state }: { state?: string; }): Promise<void> {
|
|
422
|
+
...
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
*/
|
|
427
|
+
interface AuthInterface<User = any> {
|
|
428
|
+
/**
|
|
429
|
+
*
|
|
430
|
+
* @param redirect: route that will be returned after successful authentication
|
|
431
|
+
* @param client_id: oauth client id
|
|
432
|
+
* @param callback_api: api route for callback
|
|
433
|
+
* @returns sign in url
|
|
434
|
+
*/
|
|
435
|
+
getSignInUrl({ redirect, client_id, callback_api, }: {
|
|
436
|
+
redirect?: string;
|
|
437
|
+
client_id?: string;
|
|
438
|
+
callback_api?: string;
|
|
439
|
+
}): string;
|
|
440
|
+
/**
|
|
441
|
+
* Authenticate a user
|
|
442
|
+
*/
|
|
443
|
+
signin({ username, email, password, redirect, }: {
|
|
444
|
+
username: string;
|
|
445
|
+
email?: string;
|
|
446
|
+
password: string;
|
|
447
|
+
redirect?: string;
|
|
448
|
+
}): Promise<void>;
|
|
449
|
+
/**
|
|
450
|
+
* Validate user authentication
|
|
451
|
+
*/
|
|
452
|
+
validate({ state }: {
|
|
453
|
+
state?: string;
|
|
454
|
+
}): Promise<User>;
|
|
455
|
+
/**
|
|
456
|
+
* Sign a user out
|
|
457
|
+
*/
|
|
458
|
+
signout({ state }: {
|
|
459
|
+
state?: string;
|
|
460
|
+
}): Promise<void>;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
type SessionType = {
|
|
464
|
+
username?: string;
|
|
465
|
+
email?: string;
|
|
466
|
+
role?: string;
|
|
467
|
+
} | undefined;
|
|
468
|
+
type SessionContextType = {
|
|
469
|
+
isLoading: boolean;
|
|
470
|
+
session: SessionType;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* This interface provides a guide to design storage object used for client side to operate storage operations
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
*
|
|
478
|
+
* class storage implements StorageInterface {
|
|
479
|
+
getToken(): string | null {
|
|
480
|
+
...
|
|
481
|
+
}
|
|
482
|
+
getUser(): SessionType | null {
|
|
483
|
+
...
|
|
484
|
+
}
|
|
485
|
+
setToken({ token }: { token: string; }): void {
|
|
486
|
+
...
|
|
487
|
+
}
|
|
488
|
+
removeToken(): void {
|
|
489
|
+
...
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
*/
|
|
493
|
+
interface StorageInterface {
|
|
494
|
+
getToken(): string | null;
|
|
495
|
+
getUser(): SessionType | null;
|
|
496
|
+
setToken({ token }: {
|
|
497
|
+
token: string;
|
|
498
|
+
}): void;
|
|
499
|
+
removeToken(): void;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Will-Auth - retrieve session
|
|
504
|
+
* @returns session context
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
*
|
|
508
|
+
* const { isLoading, session } = useSession()
|
|
509
|
+
*/
|
|
510
|
+
declare function useSession(): SessionContextType;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Custom Session Provider using React Context
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
*
|
|
517
|
+
* <SessionProvider value={useAuthClient(auth)}>
|
|
518
|
+
* ...
|
|
519
|
+
* </SessionProvider>
|
|
520
|
+
* // auth object implementing AuthInterface
|
|
521
|
+
*/
|
|
522
|
+
declare const SessionProvider: ({ value, children, }: {
|
|
523
|
+
value: SessionContextType;
|
|
524
|
+
children: ReactNode;
|
|
525
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Custom hook for auth
|
|
529
|
+
* - Copyright: Will Phan
|
|
530
|
+
* @param auth Auth object implementing AuthInterface
|
|
531
|
+
* @returns SessionContextType
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
*
|
|
535
|
+
* const authClient = new auth() // auth class implements AuthInterface
|
|
536
|
+
* const { isLoading, session } = useAuthClient(authClient) // auth is an auth object
|
|
537
|
+
*
|
|
538
|
+
*/
|
|
539
|
+
declare const useAuthClient: (auth: AuthInterface<SessionType>) => SessionContextType;
|
|
540
|
+
|
|
541
|
+
export { type AuthInterface, Avatar, Button, Canvas, ColorPickerSlider, DropdownSelect, Image$1 as Image, ImageEditor, Image as ImageUtilities, InputFile, InputGoogle, MultiSelect, OptionSlider, type Options$2 as Options, RangeSlider, SessionProvider, type SessionType, type Options$1 as SliderOptions, type StorageInterface, TextArea, Transform, UploadImage, tools, useAuthClient, useSession };
|
package/dist/index.js
CHANGED
|
@@ -397,6 +397,9 @@ __export(index_exports, {
|
|
|
397
397
|
RangeSlider: function() {
|
|
398
398
|
return RangeSlider_default;
|
|
399
399
|
},
|
|
400
|
+
SessionProvider: function() {
|
|
401
|
+
return SessionProvider_default;
|
|
402
|
+
},
|
|
400
403
|
TextArea: function() {
|
|
401
404
|
return TextArea_default;
|
|
402
405
|
},
|
|
@@ -405,6 +408,15 @@ __export(index_exports, {
|
|
|
405
408
|
},
|
|
406
409
|
UploadImage: function() {
|
|
407
410
|
return UploadImage_default;
|
|
411
|
+
},
|
|
412
|
+
tools: function() {
|
|
413
|
+
return tools_default;
|
|
414
|
+
},
|
|
415
|
+
useAuthClient: function() {
|
|
416
|
+
return useAuthClient_default;
|
|
417
|
+
},
|
|
418
|
+
useSession: function() {
|
|
419
|
+
return useSession;
|
|
408
420
|
}
|
|
409
421
|
});
|
|
410
422
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -3008,6 +3020,118 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
3008
3020
|
]);
|
|
3009
3021
|
return Transform;
|
|
3010
3022
|
}();
|
|
3023
|
+
// src/utilities/tools/handleAsync.ts
|
|
3024
|
+
function handleAsync(data) {
|
|
3025
|
+
return _async_to_generator(function() {
|
|
3026
|
+
var dataAsync, error;
|
|
3027
|
+
return _ts_generator(this, function(_state) {
|
|
3028
|
+
switch(_state.label){
|
|
3029
|
+
case 0:
|
|
3030
|
+
_state.trys.push([
|
|
3031
|
+
0,
|
|
3032
|
+
2,
|
|
3033
|
+
,
|
|
3034
|
+
3
|
|
3035
|
+
]);
|
|
3036
|
+
return [
|
|
3037
|
+
4,
|
|
3038
|
+
data
|
|
3039
|
+
];
|
|
3040
|
+
case 1:
|
|
3041
|
+
dataAsync = _state.sent();
|
|
3042
|
+
return [
|
|
3043
|
+
2,
|
|
3044
|
+
{
|
|
3045
|
+
error: void 0,
|
|
3046
|
+
data: dataAsync
|
|
3047
|
+
}
|
|
3048
|
+
];
|
|
3049
|
+
case 2:
|
|
3050
|
+
error = _state.sent();
|
|
3051
|
+
return [
|
|
3052
|
+
2,
|
|
3053
|
+
{
|
|
3054
|
+
error: error,
|
|
3055
|
+
data: void 0
|
|
3056
|
+
}
|
|
3057
|
+
];
|
|
3058
|
+
case 3:
|
|
3059
|
+
return [
|
|
3060
|
+
2
|
|
3061
|
+
];
|
|
3062
|
+
}
|
|
3063
|
+
});
|
|
3064
|
+
})();
|
|
3065
|
+
}
|
|
3066
|
+
var handleAsync_default = handleAsync;
|
|
3067
|
+
// src/utilities/tools/tools.ts
|
|
3068
|
+
var tools = {
|
|
3069
|
+
handleAsync: handleAsync_default
|
|
3070
|
+
};
|
|
3071
|
+
var tools_default = tools;
|
|
3072
|
+
// src/auth/react/context.tsx
|
|
3073
|
+
var import_react15 = require("react");
|
|
3074
|
+
var SessionContext = (0, import_react15.createContext)(void 0);
|
|
3075
|
+
function useSession() {
|
|
3076
|
+
var data = (0, import_react15.useContext)(SessionContext);
|
|
3077
|
+
if (data === void 0) throw new Error("Session context is undefined");
|
|
3078
|
+
return data;
|
|
3079
|
+
}
|
|
3080
|
+
// src/auth/react/SessionProvider.tsx
|
|
3081
|
+
var import_jsx_runtime20 = require("react/jsx-runtime");
|
|
3082
|
+
var SessionProvider = function(param) {
|
|
3083
|
+
var value = param.value, children = param.children;
|
|
3084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SessionContext.Provider, {
|
|
3085
|
+
value: value,
|
|
3086
|
+
children: children
|
|
3087
|
+
});
|
|
3088
|
+
};
|
|
3089
|
+
var SessionProvider_default = SessionProvider;
|
|
3090
|
+
// src/auth/react/useAuthClient.ts
|
|
3091
|
+
var import_react16 = require("react");
|
|
3092
|
+
var useAuthClient = function(auth) {
|
|
3093
|
+
var _ref = _sliced_to_array((0, import_react16.useState)(false), 2), isLoading = _ref[0], setLoading = _ref[1];
|
|
3094
|
+
var sessionRef = (0, import_react16.useRef)(void 0);
|
|
3095
|
+
(0, import_react16.useEffect)(function() {
|
|
3096
|
+
var is = true;
|
|
3097
|
+
var getSession = function() {
|
|
3098
|
+
return _async_to_generator(function() {
|
|
3099
|
+
var _ref, error, session;
|
|
3100
|
+
return _ts_generator(this, function(_state) {
|
|
3101
|
+
switch(_state.label){
|
|
3102
|
+
case 0:
|
|
3103
|
+
setLoading(true);
|
|
3104
|
+
return [
|
|
3105
|
+
4,
|
|
3106
|
+
tools_default.handleAsync(auth.validate({}))
|
|
3107
|
+
];
|
|
3108
|
+
case 1:
|
|
3109
|
+
_ref = _state.sent(), error = _ref.error, session = _ref.data;
|
|
3110
|
+
if (error) {
|
|
3111
|
+
setLoading(false);
|
|
3112
|
+
}
|
|
3113
|
+
if (is) {
|
|
3114
|
+
sessionRef.current = session;
|
|
3115
|
+
setLoading(false);
|
|
3116
|
+
}
|
|
3117
|
+
return [
|
|
3118
|
+
2
|
|
3119
|
+
];
|
|
3120
|
+
}
|
|
3121
|
+
});
|
|
3122
|
+
})();
|
|
3123
|
+
};
|
|
3124
|
+
getSession();
|
|
3125
|
+
return function() {
|
|
3126
|
+
is = false;
|
|
3127
|
+
};
|
|
3128
|
+
}, []);
|
|
3129
|
+
return {
|
|
3130
|
+
isLoading: isLoading,
|
|
3131
|
+
session: sessionRef.current
|
|
3132
|
+
};
|
|
3133
|
+
};
|
|
3134
|
+
var useAuthClient_default = useAuthClient;
|
|
3011
3135
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3012
3136
|
0 && (module.exports = {
|
|
3013
3137
|
Avatar: Avatar,
|
|
@@ -3023,7 +3147,11 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
3023
3147
|
MultiSelect: MultiSelect,
|
|
3024
3148
|
OptionSlider: OptionSlider,
|
|
3025
3149
|
RangeSlider: RangeSlider,
|
|
3150
|
+
SessionProvider: SessionProvider,
|
|
3026
3151
|
TextArea: TextArea,
|
|
3027
3152
|
Transform: Transform,
|
|
3028
|
-
UploadImage: UploadImage
|
|
3153
|
+
UploadImage: UploadImage,
|
|
3154
|
+
tools: tools,
|
|
3155
|
+
useAuthClient: useAuthClient,
|
|
3156
|
+
useSession: useSession
|
|
3029
3157
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2895,4 +2895,116 @@ var Transform = /*#__PURE__*/ function() {
|
|
|
2895
2895
|
]);
|
|
2896
2896
|
return Transform;
|
|
2897
2897
|
}();
|
|
2898
|
-
|
|
2898
|
+
// src/utilities/tools/handleAsync.ts
|
|
2899
|
+
function handleAsync(data) {
|
|
2900
|
+
return _async_to_generator(function() {
|
|
2901
|
+
var dataAsync, error;
|
|
2902
|
+
return _ts_generator(this, function(_state) {
|
|
2903
|
+
switch(_state.label){
|
|
2904
|
+
case 0:
|
|
2905
|
+
_state.trys.push([
|
|
2906
|
+
0,
|
|
2907
|
+
2,
|
|
2908
|
+
,
|
|
2909
|
+
3
|
|
2910
|
+
]);
|
|
2911
|
+
return [
|
|
2912
|
+
4,
|
|
2913
|
+
data
|
|
2914
|
+
];
|
|
2915
|
+
case 1:
|
|
2916
|
+
dataAsync = _state.sent();
|
|
2917
|
+
return [
|
|
2918
|
+
2,
|
|
2919
|
+
{
|
|
2920
|
+
error: void 0,
|
|
2921
|
+
data: dataAsync
|
|
2922
|
+
}
|
|
2923
|
+
];
|
|
2924
|
+
case 2:
|
|
2925
|
+
error = _state.sent();
|
|
2926
|
+
return [
|
|
2927
|
+
2,
|
|
2928
|
+
{
|
|
2929
|
+
error: error,
|
|
2930
|
+
data: void 0
|
|
2931
|
+
}
|
|
2932
|
+
];
|
|
2933
|
+
case 3:
|
|
2934
|
+
return [
|
|
2935
|
+
2
|
|
2936
|
+
];
|
|
2937
|
+
}
|
|
2938
|
+
});
|
|
2939
|
+
})();
|
|
2940
|
+
}
|
|
2941
|
+
var handleAsync_default = handleAsync;
|
|
2942
|
+
// src/utilities/tools/tools.ts
|
|
2943
|
+
var tools = {
|
|
2944
|
+
handleAsync: handleAsync_default
|
|
2945
|
+
};
|
|
2946
|
+
var tools_default = tools;
|
|
2947
|
+
// src/auth/react/context.tsx
|
|
2948
|
+
import { createContext as createContext4, useContext as useContext4 } from "react";
|
|
2949
|
+
var SessionContext = createContext4(void 0);
|
|
2950
|
+
function useSession() {
|
|
2951
|
+
var data = useContext4(SessionContext);
|
|
2952
|
+
if (data === void 0) throw new Error("Session context is undefined");
|
|
2953
|
+
return data;
|
|
2954
|
+
}
|
|
2955
|
+
// src/auth/react/SessionProvider.tsx
|
|
2956
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
2957
|
+
var SessionProvider = function(param) {
|
|
2958
|
+
var value = param.value, children = param.children;
|
|
2959
|
+
return /* @__PURE__ */ jsx20(SessionContext.Provider, {
|
|
2960
|
+
value: value,
|
|
2961
|
+
children: children
|
|
2962
|
+
});
|
|
2963
|
+
};
|
|
2964
|
+
var SessionProvider_default = SessionProvider;
|
|
2965
|
+
// src/auth/react/useAuthClient.ts
|
|
2966
|
+
import { useEffect as useEffect11, useRef as useRef11, useState as useState12 } from "react";
|
|
2967
|
+
var useAuthClient = function(auth) {
|
|
2968
|
+
var _useState12 = _sliced_to_array(useState12(false), 2), isLoading = _useState12[0], setLoading = _useState12[1];
|
|
2969
|
+
var sessionRef = useRef11(void 0);
|
|
2970
|
+
useEffect11(function() {
|
|
2971
|
+
var is = true;
|
|
2972
|
+
var getSession = function() {
|
|
2973
|
+
return _async_to_generator(function() {
|
|
2974
|
+
var _ref, error, session;
|
|
2975
|
+
return _ts_generator(this, function(_state) {
|
|
2976
|
+
switch(_state.label){
|
|
2977
|
+
case 0:
|
|
2978
|
+
setLoading(true);
|
|
2979
|
+
return [
|
|
2980
|
+
4,
|
|
2981
|
+
tools_default.handleAsync(auth.validate({}))
|
|
2982
|
+
];
|
|
2983
|
+
case 1:
|
|
2984
|
+
_ref = _state.sent(), error = _ref.error, session = _ref.data;
|
|
2985
|
+
if (error) {
|
|
2986
|
+
setLoading(false);
|
|
2987
|
+
}
|
|
2988
|
+
if (is) {
|
|
2989
|
+
sessionRef.current = session;
|
|
2990
|
+
setLoading(false);
|
|
2991
|
+
}
|
|
2992
|
+
return [
|
|
2993
|
+
2
|
|
2994
|
+
];
|
|
2995
|
+
}
|
|
2996
|
+
});
|
|
2997
|
+
})();
|
|
2998
|
+
};
|
|
2999
|
+
getSession();
|
|
3000
|
+
return function() {
|
|
3001
|
+
is = false;
|
|
3002
|
+
};
|
|
3003
|
+
}, []);
|
|
3004
|
+
return {
|
|
3005
|
+
isLoading: isLoading,
|
|
3006
|
+
session: sessionRef.current
|
|
3007
|
+
};
|
|
3008
|
+
};
|
|
3009
|
+
var useAuthClient_default = useAuthClient;
|
|
3010
|
+
export { Avatar_default as Avatar, Button_default as Button, Canvas, ColorPickerSlider_default as ColorPickerSlider, DropdownSelect_default as DropdownSelect, Image_default as Image, ImageEditor_default as ImageEditor, Image_default2 as ImageUtilities, InputFile_default as InputFile, InputGoogle_default as InputGoogle, MultiSelect_default as MultiSelect, OptionSlider_default as OptionSlider, RangeSlider_default as RangeSlider, SessionProvider_default as SessionProvider, TextArea_default as TextArea, Transform, UploadImage_default as UploadImage, tools_default as tools, useAuthClient_default as useAuthClient, useSession };
|