@temboplus/afloat 0.1.77-beta.18 → 0.1.77-beta.20
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.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/api/base-repository.d.ts +3 -1
- package/dist/modules/auth/auth.contract.d.ts +2 -2
- package/dist/modules/auth/company-membership.model.d.ts +4 -4
- package/dist/modules/auth/index.d.ts +0 -1
- package/dist/modules/auth/user.model.d.ts +10 -10
- package/dist/modules/contact/contact.api-contract.d.ts +8 -8
- package/dist/modules/contact/contact.dtos.d.ts +2 -2
- package/dist/modules/contact/contact.model.d.ts +4 -4
- package/dist/modules/login/login.api-contract.d.ts +2 -2
- package/dist/modules/login/login.dtos.d.ts +4 -4
- package/dist/modules/login/login.model.d.ts +2 -2
- package/dist/modules/payout/payout.api-contract.d.ts +37 -37
- package/dist/modules/payout/payout.dtos.d.ts +26 -26
- package/dist/modules/payout/payout.model.d.ts +6 -6
- package/dist/modules/payout/payout.repository.d.ts +13 -2
- package/dist/modules/team-member/role.model.d.ts +2 -2
- package/dist/modules/team-member/team-member.contract.d.ts +44 -44
- package/dist/modules/team-member/team-member.dtos.d.ts +14 -14
- package/dist/modules/team-member/team-member.model.d.ts +6 -6
- package/dist/modules/wallet/index.d.ts +0 -1
- package/dist/modules/wallet/wallet.contract.d.ts +6 -6
- package/dist/modules/wallet/wallet.dtos.d.ts +12 -12
- package/dist/modules/wallet/wallet.model.d.ts +4 -4
- package/package.json +1 -1
- package/dist/modules/auth/auth.manager.d.ts +0 -249
- package/dist/modules/auth/auth.store.d.ts +0 -139
- package/dist/modules/auth/storage/client-store.d.ts +0 -29
- package/dist/modules/auth/storage/client-token-handler.d.ts +0 -31
- package/dist/modules/auth/storage/types.d.ts +0 -41
- package/dist/modules/wallet/wallet-manager.session.d.ts +0 -143
|
@@ -15,23 +15,23 @@ declare const walletSchema: z.ZodObject<{
|
|
|
15
15
|
createdAt: z.ZodString;
|
|
16
16
|
updatedAt: z.ZodString;
|
|
17
17
|
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
createdAt: string;
|
|
18
19
|
id: string;
|
|
19
20
|
accountNo: string;
|
|
20
21
|
profileId: string;
|
|
21
|
-
createdAt: string;
|
|
22
22
|
updatedAt: string;
|
|
23
|
-
accountName: string;
|
|
24
23
|
channel: string;
|
|
25
24
|
countryCode: import("@temboplus/frontend-core").ISO2CountryCode;
|
|
26
25
|
currencyCode: import("@temboplus/frontend-core").CurrencyCode;
|
|
26
|
+
accountName: string;
|
|
27
27
|
}, {
|
|
28
|
+
createdAt: string;
|
|
28
29
|
id: string;
|
|
29
30
|
accountNo: string;
|
|
30
31
|
profileId: string;
|
|
31
|
-
createdAt: string;
|
|
32
32
|
updatedAt: string;
|
|
33
|
-
accountName: string;
|
|
34
33
|
channel: string;
|
|
34
|
+
accountName: string;
|
|
35
35
|
countryCode?: string | undefined;
|
|
36
36
|
currencyCode?: string | undefined;
|
|
37
37
|
}>;
|
|
@@ -52,18 +52,18 @@ declare const walletQuerySchema: z.ZodObject<{
|
|
|
52
52
|
id?: string | undefined;
|
|
53
53
|
accountNo?: string | undefined;
|
|
54
54
|
profileId?: string | undefined;
|
|
55
|
-
accountName?: string | undefined;
|
|
56
55
|
channel?: string | undefined;
|
|
57
56
|
countryCode?: string | undefined;
|
|
58
57
|
currencyCode?: string | undefined;
|
|
58
|
+
accountName?: string | undefined;
|
|
59
59
|
}, {
|
|
60
60
|
id?: string | undefined;
|
|
61
61
|
accountNo?: string | undefined;
|
|
62
62
|
profileId?: string | undefined;
|
|
63
|
-
accountName?: string | undefined;
|
|
64
63
|
channel?: string | undefined;
|
|
65
64
|
countryCode?: string | undefined;
|
|
66
65
|
currencyCode?: string | undefined;
|
|
66
|
+
accountName?: string | undefined;
|
|
67
67
|
}>;
|
|
68
68
|
/**
|
|
69
69
|
* Schema definition for a statement entry.
|
|
@@ -118,23 +118,23 @@ export declare const WalletDTOSchemas: {
|
|
|
118
118
|
createdAt: z.ZodString;
|
|
119
119
|
updatedAt: z.ZodString;
|
|
120
120
|
}, "strip", z.ZodTypeAny, {
|
|
121
|
+
createdAt: string;
|
|
121
122
|
id: string;
|
|
122
123
|
accountNo: string;
|
|
123
124
|
profileId: string;
|
|
124
|
-
createdAt: string;
|
|
125
125
|
updatedAt: string;
|
|
126
|
-
accountName: string;
|
|
127
126
|
channel: string;
|
|
128
127
|
countryCode: import("@temboplus/frontend-core").ISO2CountryCode;
|
|
129
128
|
currencyCode: import("@temboplus/frontend-core").CurrencyCode;
|
|
129
|
+
accountName: string;
|
|
130
130
|
}, {
|
|
131
|
+
createdAt: string;
|
|
131
132
|
id: string;
|
|
132
133
|
accountNo: string;
|
|
133
134
|
profileId: string;
|
|
134
|
-
createdAt: string;
|
|
135
135
|
updatedAt: string;
|
|
136
|
-
accountName: string;
|
|
137
136
|
channel: string;
|
|
137
|
+
accountName: string;
|
|
138
138
|
countryCode?: string | undefined;
|
|
139
139
|
currencyCode?: string | undefined;
|
|
140
140
|
}>;
|
|
@@ -150,18 +150,18 @@ export declare const WalletDTOSchemas: {
|
|
|
150
150
|
id?: string | undefined;
|
|
151
151
|
accountNo?: string | undefined;
|
|
152
152
|
profileId?: string | undefined;
|
|
153
|
-
accountName?: string | undefined;
|
|
154
153
|
channel?: string | undefined;
|
|
155
154
|
countryCode?: string | undefined;
|
|
156
155
|
currencyCode?: string | undefined;
|
|
156
|
+
accountName?: string | undefined;
|
|
157
157
|
}, {
|
|
158
158
|
id?: string | undefined;
|
|
159
159
|
accountNo?: string | undefined;
|
|
160
160
|
profileId?: string | undefined;
|
|
161
|
-
accountName?: string | undefined;
|
|
162
161
|
channel?: string | undefined;
|
|
163
162
|
countryCode?: string | undefined;
|
|
164
163
|
currencyCode?: string | undefined;
|
|
164
|
+
accountName?: string | undefined;
|
|
165
165
|
}>;
|
|
166
166
|
statementEntry: z.ZodObject<{
|
|
167
167
|
accountNo: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
@@ -16,26 +16,26 @@ export declare const WalletJSONSchema: z.ZodObject<{
|
|
|
16
16
|
updatedAt: z.ZodString;
|
|
17
17
|
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
18
|
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
createdAt: string;
|
|
19
20
|
id: string;
|
|
20
21
|
accountNo: string;
|
|
21
22
|
version: string;
|
|
22
23
|
profileId: string;
|
|
23
|
-
createdAt: string;
|
|
24
24
|
updatedAt: string;
|
|
25
|
-
accountName: string;
|
|
26
25
|
channel: string;
|
|
27
26
|
countryCode: string;
|
|
28
27
|
currencyCode: string;
|
|
28
|
+
accountName: string;
|
|
29
29
|
}, {
|
|
30
|
+
createdAt: string;
|
|
30
31
|
id: string;
|
|
31
32
|
accountNo: string;
|
|
32
33
|
profileId: string;
|
|
33
|
-
createdAt: string;
|
|
34
34
|
updatedAt: string;
|
|
35
|
-
accountName: string;
|
|
36
35
|
channel: string;
|
|
37
36
|
countryCode: string;
|
|
38
37
|
currencyCode: string;
|
|
38
|
+
accountName: string;
|
|
39
39
|
version?: string | undefined;
|
|
40
40
|
}>;
|
|
41
41
|
export type WalletJSON = z.infer<typeof WalletJSONSchema>;
|
package/package.json
CHANGED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import { Permission } from "@/modules/login/permission.type.js";
|
|
2
|
-
import { User } from "@/modules/auth/user.model.js";
|
|
3
|
-
/**
|
|
4
|
-
* Clean authentication manager for client-side usage only.
|
|
5
|
-
*
|
|
6
|
-
* This class provides a centralized way to manage user authentication state,
|
|
7
|
-
* including login, logout, and permission checking. It uses a singleton pattern
|
|
8
|
-
* for client-side usage and directly interfaces with the unified auth store.
|
|
9
|
-
*
|
|
10
|
-
* **Architecture:**
|
|
11
|
-
* - **Client-side**: Use the singleton instance via `AfloatAuth.instance`
|
|
12
|
-
* - **Server-side**: Pass tokens directly to repositories (no auth manager needed)
|
|
13
|
-
*
|
|
14
|
-
* **Features:**
|
|
15
|
-
* - Direct integration with unified auth store
|
|
16
|
-
* - React hooks for reactive UI updates
|
|
17
|
-
* - Permission checking utilities
|
|
18
|
-
* - Automatic wallet session management
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* // Client-side usage
|
|
23
|
-
* const auth = AfloatAuth.instance;
|
|
24
|
-
* const user = await auth.logIn(email, password);
|
|
25
|
-
*
|
|
26
|
-
* // Server-side usage (no auth manager needed)
|
|
27
|
-
* const walletRepo = new WalletRepository({ token: extractedToken });
|
|
28
|
-
* const balance = await walletRepo.getBalance({ wallet });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare class AfloatAuth {
|
|
32
|
-
/** Client-side singleton instance */
|
|
33
|
-
private static _instance;
|
|
34
|
-
/**
|
|
35
|
-
* Private constructor to control instantiation.
|
|
36
|
-
* Use the static instance getter instead.
|
|
37
|
-
*
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
private constructor();
|
|
41
|
-
/**
|
|
42
|
-
* Gets or creates the client-side singleton instance.
|
|
43
|
-
*
|
|
44
|
-
* @returns The client-side singleton instance
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* const auth = AfloatAuth.instance;
|
|
49
|
-
* if (auth.currentUser) {
|
|
50
|
-
* console.log("User is logged in");
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
static get instance(): AfloatAuth;
|
|
55
|
-
/**
|
|
56
|
-
* Gets the authentication repository for API operations.
|
|
57
|
-
*
|
|
58
|
-
* @private
|
|
59
|
-
* @returns The auth repository instance with current token
|
|
60
|
-
*/
|
|
61
|
-
private get repo();
|
|
62
|
-
/**
|
|
63
|
-
* Gets the current authentication token.
|
|
64
|
-
*
|
|
65
|
-
* @returns The current authentication token, or undefined if not authenticated
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const token = auth.getUserToken();
|
|
70
|
-
* if (token) {
|
|
71
|
-
* const apiClient = new SomeRepository({ token });
|
|
72
|
-
* }
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
getUserToken(): string | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Gets the currently authenticated user.
|
|
78
|
-
*
|
|
79
|
-
* @returns The current user instance, or undefined if not authenticated
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const user = auth.currentUser;
|
|
84
|
-
* if (user) {
|
|
85
|
-
* console.log(`Welcome, ${user.name}!`);
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
get currentUser(): User | undefined;
|
|
90
|
-
/**
|
|
91
|
-
* Checks if a user is currently authenticated.
|
|
92
|
-
*
|
|
93
|
-
* @returns True if user is authenticated, false otherwise
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* if (auth.isAuthenticated) {
|
|
98
|
-
* // User is logged in
|
|
99
|
-
* showDashboard();
|
|
100
|
-
* } else {
|
|
101
|
-
* // User needs to log in
|
|
102
|
-
* showLoginForm();
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
get isAuthenticated(): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* React hook for accessing the current user in client-side components.
|
|
109
|
-
*
|
|
110
|
-
* This hook provides reactive updates when the user state changes,
|
|
111
|
-
* making it perfect for React components that need to respond to
|
|
112
|
-
* authentication state changes.
|
|
113
|
-
*
|
|
114
|
-
* @returns The current user with reactive updates, or undefined if not authenticated
|
|
115
|
-
* @throws {Error} If called in a server environment
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* function UserProfile() {
|
|
120
|
-
* const user = AfloatAuth.instance.useCurrentUser();
|
|
121
|
-
*
|
|
122
|
-
* if (!user) {
|
|
123
|
-
* return <LoginForm />;
|
|
124
|
-
* }
|
|
125
|
-
*
|
|
126
|
-
* return <div>Hello, {user.name}!</div>;
|
|
127
|
-
* }
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
useCurrentUser(): User | undefined;
|
|
131
|
-
/**
|
|
132
|
-
* Checks if the current user has a specific permission.
|
|
133
|
-
*
|
|
134
|
-
* @param perm - The permission to check
|
|
135
|
-
* @returns True if the user has the permission, false otherwise
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* if (auth.checkPermission(Permission.ViewBalance)) {
|
|
140
|
-
* // User can view wallet balance
|
|
141
|
-
* const walletRepo = new WalletRepository({ token: auth.getUserToken() });
|
|
142
|
-
* const balance = await walletRepo.getBalance(wallet);
|
|
143
|
-
* } else {
|
|
144
|
-
* console.log("User doesn't have permission to view balance");
|
|
145
|
-
* }
|
|
146
|
-
* ```
|
|
147
|
-
*/
|
|
148
|
-
checkPermission(perm: Permission): boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Authenticates a user with email and password.
|
|
151
|
-
*
|
|
152
|
-
* On successful authentication:
|
|
153
|
-
* - Clears any existing auth data
|
|
154
|
-
* - Stores the new user and token atomically
|
|
155
|
-
* - Initializes related services (wallet manager)
|
|
156
|
-
*
|
|
157
|
-
* @param email - The user's email address
|
|
158
|
-
* @param password - The user's password
|
|
159
|
-
* @returns Promise resolving to the authenticated user
|
|
160
|
-
* @throws {Error} If authentication fails
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```typescript
|
|
164
|
-
* try {
|
|
165
|
-
* const user = await auth.logIn("user@example.com", "password123");
|
|
166
|
-
* console.log("Login successful!");
|
|
167
|
-
* router.push("/dashboard");
|
|
168
|
-
* } catch (error) {
|
|
169
|
-
* console.error("Login failed:", error.message);
|
|
170
|
-
* setError("Invalid credentials");
|
|
171
|
-
* }
|
|
172
|
-
* ```
|
|
173
|
-
*/
|
|
174
|
-
logIn(email: string, password: string): Promise<User>;
|
|
175
|
-
/**
|
|
176
|
-
* Updates the current user's password.
|
|
177
|
-
*
|
|
178
|
-
* @param currentPassword - The user's current password
|
|
179
|
-
* @param newPassword - The new password to set
|
|
180
|
-
* @returns Promise resolving to true if successful
|
|
181
|
-
* @throws {Error} If the password update fails or user is not authenticated
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* try {
|
|
186
|
-
* await auth.resetPassword("oldPassword", "newPassword123");
|
|
187
|
-
* console.log("Password updated successfully");
|
|
188
|
-
* showSuccessMessage("Password updated!");
|
|
189
|
-
* } catch (error) {
|
|
190
|
-
* console.error("Password update failed:", error.message);
|
|
191
|
-
* showErrorMessage("Failed to update password");
|
|
192
|
-
* }
|
|
193
|
-
* ```
|
|
194
|
-
*/
|
|
195
|
-
resetPassword(currentPassword: string, newPassword: string): Promise<boolean>;
|
|
196
|
-
/**
|
|
197
|
-
* Logs out the current user and clears all authentication data.
|
|
198
|
-
*
|
|
199
|
-
* This method:
|
|
200
|
-
* - Clears user state from memory and storage
|
|
201
|
-
* - Removes authentication tokens
|
|
202
|
-
* - Resets related services
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* auth.logOut();
|
|
207
|
-
* router.push("/login");
|
|
208
|
-
* console.log("User logged out successfully");
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
logOut(): void;
|
|
212
|
-
/**
|
|
213
|
-
* Refreshes the current authentication state.
|
|
214
|
-
* Useful for clearing potentially stale data.
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
* // Clear current state and force fresh authentication
|
|
219
|
-
* auth.refresh();
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
refresh(): void;
|
|
223
|
-
/**
|
|
224
|
-
* Gets debug information about the current authentication state.
|
|
225
|
-
* Useful for troubleshooting authentication issues.
|
|
226
|
-
*
|
|
227
|
-
* @returns Object containing authentication state information
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* const debugInfo = auth.getDebugInfo();
|
|
232
|
-
* console.log("Auth Debug Info:", debugInfo);
|
|
233
|
-
* ```
|
|
234
|
-
*/
|
|
235
|
-
getDebugInfo(): {
|
|
236
|
-
hasUser: boolean;
|
|
237
|
-
hasToken: boolean;
|
|
238
|
-
isAuthenticated: boolean;
|
|
239
|
-
userName: string;
|
|
240
|
-
tokenLength: number;
|
|
241
|
-
managerInstance: string;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Clears all stored authentication data from the unified store.
|
|
245
|
-
*
|
|
246
|
-
* @private
|
|
247
|
-
*/
|
|
248
|
-
private clearSavedData;
|
|
249
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { type StoreApi, type UseBoundStore } from "zustand";
|
|
2
|
-
import { User } from "@/modules/auth/user.model.js";
|
|
3
|
-
/** Type definition for the store's internal state */
|
|
4
|
-
type AuthState = {
|
|
5
|
-
user: string | undefined;
|
|
6
|
-
token: string | undefined;
|
|
7
|
-
};
|
|
8
|
-
/** Type definition for the store's actions */
|
|
9
|
-
interface AuthActions {
|
|
10
|
-
setUser: (user: User) => void;
|
|
11
|
-
getUser: () => User | undefined;
|
|
12
|
-
setToken: (token: string) => void;
|
|
13
|
-
getToken: () => string | undefined;
|
|
14
|
-
setUserAndToken: (user: User, token: string) => void;
|
|
15
|
-
clearAuth: () => void;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Unified Zustand store for managing both user and token state with persistence.
|
|
19
|
-
*
|
|
20
|
-
* Features:
|
|
21
|
-
* - Persists both user data and token to sessionStorage
|
|
22
|
-
* - Serializes/deserializes User objects to/from JSON
|
|
23
|
-
* - Provides reactive state updates for React components
|
|
24
|
-
* - Automatically syncs user and token state
|
|
25
|
-
* - Server-side rendering safe
|
|
26
|
-
*/
|
|
27
|
-
export declare const authStore: UseBoundStore<StoreApi<AuthState & AuthActions>>;
|
|
28
|
-
/**
|
|
29
|
-
* Gets the current authenticated user from the auth store.
|
|
30
|
-
* This function can be called from anywhere in the application.
|
|
31
|
-
*
|
|
32
|
-
* @returns The current user or undefined if not authenticated
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* // In BaseRepository or any other file
|
|
37
|
-
* const user = getCurrentUser();
|
|
38
|
-
* if (user) {
|
|
39
|
-
* console.log(`Current user: ${user.name}`);
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare const getCurrentUser: () => User | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Gets the current authentication token from the auth store.
|
|
46
|
-
* This function can be called from anywhere in the application,
|
|
47
|
-
* including BaseRepository for automatic token injection.
|
|
48
|
-
*
|
|
49
|
-
* @returns The current token or undefined if not authenticated
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* // In BaseRepository
|
|
54
|
-
* const token = getCurrentToken();
|
|
55
|
-
* if (token) {
|
|
56
|
-
* // Use token for API calls
|
|
57
|
-
* return initClient(contract, { baseHeaders: { token } });
|
|
58
|
-
* }
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare const getCurrentToken: () => string | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* React hook to access the current user with reactive updates.
|
|
64
|
-
*
|
|
65
|
-
* @returns The current user or undefined if not authenticated
|
|
66
|
-
* @throws {Error} If called in a server environment
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* function UserProfile() {
|
|
71
|
-
* const user = useCurrentUser();
|
|
72
|
-
*
|
|
73
|
-
* if (!user) {
|
|
74
|
-
* return <div>Please log in</div>;
|
|
75
|
-
* }
|
|
76
|
-
*
|
|
77
|
-
* return <div>Welcome, {user.name}!</div>;
|
|
78
|
-
* }
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export declare const useCurrentUser: () => User | undefined;
|
|
82
|
-
/**
|
|
83
|
-
* React hook to access the current token with reactive updates.
|
|
84
|
-
*
|
|
85
|
-
* @returns The current token or undefined if not authenticated
|
|
86
|
-
* @throws {Error} If called in a server environment
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* function SomeComponent() {
|
|
91
|
-
* const token = useCurrentToken();
|
|
92
|
-
*
|
|
93
|
-
* if (!token) {
|
|
94
|
-
* return <div>Please log in</div>;
|
|
95
|
-
* }
|
|
96
|
-
*
|
|
97
|
-
* // Use token...
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export declare const useCurrentToken: () => string | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* Checks if a user is currently authenticated.
|
|
104
|
-
*
|
|
105
|
-
* @returns True if user is authenticated, false otherwise
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```typescript
|
|
109
|
-
* if (isAuthenticated()) {
|
|
110
|
-
* // User is logged in
|
|
111
|
-
* showDashboard();
|
|
112
|
-
* } else {
|
|
113
|
-
* // User needs to log in
|
|
114
|
-
* showLoginForm();
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
export declare const isAuthenticated: () => boolean;
|
|
119
|
-
/**
|
|
120
|
-
* Gets debug information about the current authentication state.
|
|
121
|
-
* Useful for troubleshooting authentication issues.
|
|
122
|
-
*
|
|
123
|
-
* @returns Object containing authentication state information
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const debugInfo = getAuthDebugInfo();
|
|
128
|
-
* console.log("Auth Debug Info:", debugInfo);
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export declare const getAuthDebugInfo: () => {
|
|
132
|
-
hasUser: boolean;
|
|
133
|
-
hasToken: boolean;
|
|
134
|
-
isAuthenticated: boolean;
|
|
135
|
-
userName: string;
|
|
136
|
-
tokenLength: number;
|
|
137
|
-
storeState: string | (AuthState & AuthActions);
|
|
138
|
-
};
|
|
139
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type StoreApi, type UseBoundStore } from "zustand";
|
|
2
|
-
import type { AuthStore } from "./types.js";
|
|
3
|
-
import { User } from "@/modules/auth/user.model.js";
|
|
4
|
-
/** Type definition for the store's state */
|
|
5
|
-
type State = {
|
|
6
|
-
user: string | undefined;
|
|
7
|
-
};
|
|
8
|
-
/** Type definition for the store's actions */
|
|
9
|
-
interface Actions {
|
|
10
|
-
setUser: (user: User) => void;
|
|
11
|
-
getUser: () => User | undefined;
|
|
12
|
-
refresh: () => void;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Creates and exports the Zustand store directly for reactive hooks
|
|
16
|
-
* @internal This should only be used by AfloatAuth
|
|
17
|
-
*/
|
|
18
|
-
export declare const clientStore: UseBoundStore<StoreApi<State & Actions>>;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a client-side authentication store using Zustand.
|
|
21
|
-
* @returns {AuthStore} An implementation of AuthStore for client-side use
|
|
22
|
-
*/
|
|
23
|
-
export declare const createClientStore: () => AuthStore;
|
|
24
|
-
/**
|
|
25
|
-
* React hook to access the current user with reactive updates.
|
|
26
|
-
* @returns {User | undefined} The current user or undefined if not authenticated
|
|
27
|
-
*/
|
|
28
|
-
export declare const useClientUser: () => User | undefined;
|
|
29
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { TokenHandler } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Client-side implementation of TokenHandler.
|
|
4
|
-
* Manages tokens using sessionStorage.
|
|
5
|
-
* @implements {TokenHandler}
|
|
6
|
-
*/
|
|
7
|
-
export declare class ClientTokenHandler implements TokenHandler {
|
|
8
|
-
/** Singleton instance */
|
|
9
|
-
private static _instance;
|
|
10
|
-
/** Private constructor to enforce singleton pattern */
|
|
11
|
-
private constructor();
|
|
12
|
-
/**
|
|
13
|
-
* Gets the singleton instance of ClientTokenHandler.
|
|
14
|
-
* @returns {ClientTokenHandler} The singleton instance
|
|
15
|
-
*/
|
|
16
|
-
static get instance(): ClientTokenHandler;
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the token from sessionStorage.
|
|
19
|
-
* @returns {string | undefined} The stored token or undefined if not present
|
|
20
|
-
*/
|
|
21
|
-
getUserToken(): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Stores the token in sessionStorage.
|
|
24
|
-
* @param {string} token - The token to store
|
|
25
|
-
*/
|
|
26
|
-
setUserToken(token: string): void;
|
|
27
|
-
/**
|
|
28
|
-
* Removes the token from sessionStorage.
|
|
29
|
-
*/
|
|
30
|
-
clearToken(): void;
|
|
31
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { User } from "../user.model.js";
|
|
2
|
-
/**
|
|
3
|
-
* Interface defining the contract for auth storage implementations.
|
|
4
|
-
* This allows for different storage strategies in different environments.
|
|
5
|
-
*/
|
|
6
|
-
export interface AuthStore {
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves the currently authenticated user.
|
|
9
|
-
* @returns {User | undefined} The current user or undefined if not authenticated
|
|
10
|
-
*/
|
|
11
|
-
getUser(): User | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* Sets the current authenticated user.
|
|
14
|
-
* @param {User} user - The user to set as currently authenticated
|
|
15
|
-
*/
|
|
16
|
-
setUser(user: User): void;
|
|
17
|
-
/**
|
|
18
|
-
* Clears the current authentication state.
|
|
19
|
-
*/
|
|
20
|
-
refresh(): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Interface defining the contract for token handling implementations.
|
|
24
|
-
* This allows for different token storage strategies in different environments.
|
|
25
|
-
*/
|
|
26
|
-
export interface TokenHandler {
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the current authentication token.
|
|
29
|
-
* @returns {string | undefined} The current token or undefined if not present
|
|
30
|
-
*/
|
|
31
|
-
getUserToken(): string | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Sets the authentication token.
|
|
34
|
-
* @param {string} token - The token to store
|
|
35
|
-
*/
|
|
36
|
-
setUserToken(token: string): void;
|
|
37
|
-
/**
|
|
38
|
-
* Clears the stored authentication token.
|
|
39
|
-
*/
|
|
40
|
-
clearToken(): void;
|
|
41
|
-
}
|