@aventoapp/framework 0.2.0 → 0.2.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 +260 -0
- package/dist/index.js.map +1 -1
- package/dist/native/index.js.map +1 -1
- package/dist/offline/index.js.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/workflow/index.js.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/web/index.js.map +1 -1
- package/package.json +84 -79
- package/schemas/Workflow.json +14 -14
- package/schemas/WorkflowHistory.json +22 -22
- package/schemas/WorkflowInstance.json +16 -16
- package/schemas/WorkflowState.json +18 -18
- package/schemas/WorkflowTransition.json +27 -27
- package/src/index.js +8 -8
- package/src/native/components/NativeAuthProvider.jsx +249 -249
- package/src/native/components/NativeDetail.jsx +270 -270
- package/src/native/components/NativeForm.jsx +543 -543
- package/src/native/components/NativeGrid.jsx +90 -90
- package/src/native/components/NativeJsonGrid.jsx +213 -213
- package/src/native/components/NativeJsonView.jsx +454 -454
- package/src/native/components/NativeJsonViewContext.js +17 -17
- package/src/native/components/NativeShell.jsx +68 -68
- package/src/native/components/NativeViewComponent.jsx +351 -351
- package/src/native/extensions/NativeExtensionRegistry.js +81 -81
- package/src/native/hooks/useNativeStore.js +72 -72
- package/src/native/index.js +15 -15
- package/src/native/layouts/NativeStackLayout.jsx +30 -30
- package/src/native/layouts/NativeTabLayout.jsx +96 -96
- package/src/native/storage.js +13 -13
- package/src/native/stores/NativeBaseStore.js +348 -348
- package/src/native/stores/NativeStoreContext.jsx +53 -53
- package/src/offline/index.js +1 -1
- package/src/server/ai/capabilities-routes.js +106 -106
- package/src/server/ai/index.js +1 -1
- package/src/server/cache/MemoryCache.js +153 -153
- package/src/server/cache/index.js +2 -2
- package/src/server/cache/middleware.js +12 -12
- package/src/server/db/index.js +14 -14
- package/src/server/db/mongo.js +137 -137
- package/src/server/db/postgres.js +144 -144
- package/src/server/index.js +42 -42
- package/src/server/middleware/auth.js +682 -682
- package/src/server/middleware/can-flags.js +132 -132
- package/src/server/middleware/entityRoles.js +105 -105
- package/src/server/middleware/index.js +58 -58
- package/src/server/middleware/permissions.js +240 -240
- package/src/server/middleware/tenant.js +203 -203
- package/src/server/realtime/EventBus.js +45 -45
- package/src/server/realtime/WebSocketServer.js +105 -105
- package/src/server/realtime/index.js +3 -3
- package/src/server/realtime/middleware.js +18 -18
- package/src/server/services/email-templates.js +157 -157
- package/src/server/services/email.js +78 -78
- package/src/server/services/index.js +15 -15
- package/src/server/services/storage.js +119 -119
- package/src/server/utils/index.js +16 -16
- package/src/server/utils/paginate.js +65 -65
- package/src/server/utils/query-builder.js +293 -293
- package/src/server/utils/route-loader.js +61 -61
- package/src/server/workflow/WorkflowEngine.js +494 -494
- package/src/server/workflow/index.js +2 -2
- package/src/server/workflow/workflow-routes.js +174 -174
- package/src/shared/index.js +10 -10
- package/src/shared/utils/field-accessor.js +108 -108
- package/src/shared/utils/index.js +7 -7
- package/src/shared/utils/validation-utils.js +83 -83
- package/src/web/components/AppRouter/AppRouter.jsx +130 -130
- package/src/web/components/AppRouter/index.js +1 -1
- package/src/web/components/AppShell/AppShell.jsx +101 -101
- package/src/web/components/AppShell/DefaultUserMenu.jsx +54 -54
- package/src/web/components/AppShell/ShellConfig.js +53 -53
- package/src/web/components/AppShell/index.js +3 -3
- package/src/web/components/AuthProvider.jsx +426 -426
- package/src/web/components/CardList/CardList.jsx +272 -272
- package/src/web/components/CardList/index.js +2 -2
- package/src/web/components/DetailView/DetailView.jsx +281 -281
- package/src/web/components/DetailView/index.js +2 -2
- package/src/web/components/Form/Form.jsx +300 -300
- package/src/web/components/Form/FormField.jsx +226 -226
- package/src/web/components/Form/index.js +3 -3
- package/src/web/components/Grid/Grid.jsx +304 -304
- package/src/web/components/Grid/index.js +2 -2
- package/src/web/components/IconRegistry/IconRegistry.jsx +127 -127
- package/src/web/components/IconRegistry/index.js +1 -1
- package/src/web/components/JsonView/JsonView.jsx +647 -647
- package/src/web/components/JsonView/ViewComponent.jsx +1045 -1045
- package/src/web/components/JsonView/ViewToolbar.jsx +141 -141
- package/src/web/components/JsonView/index.js +14 -14
- package/src/web/components/JsonView/layouts/SingleLayout.jsx +41 -41
- package/src/web/components/JsonView/layouts/SplitLayout.jsx +122 -122
- package/src/web/components/JsonView/layouts/TabLayout.jsx +112 -112
- package/src/web/components/JsonView/layouts/index.js +8 -8
- package/src/web/components/Layout.jsx +265 -265
- package/src/web/components/MobileLayout/MobileLayout.jsx +385 -385
- package/src/web/components/MobileLayout/index.js +1 -1
- package/src/web/components/Navigation/Navigation.jsx +248 -248
- package/src/web/components/Navigation/index.js +1 -1
- package/src/web/components/NotificationProvider.jsx +55 -55
- package/src/web/components/Pagination/InfiniteScroll.jsx +82 -82
- package/src/web/components/Pagination/Pagination.jsx +73 -73
- package/src/web/components/Pagination/index.js +8 -8
- package/src/web/components/SimpleList/SimpleList.jsx +177 -177
- package/src/web/components/SimpleList/index.js +2 -2
- package/src/web/components/TenantProvider.jsx +121 -121
- package/src/web/components/WorkflowActions/WorkflowActions.jsx +71 -71
- package/src/web/components/WorkflowActions/index.js +1 -1
- package/src/web/components/WorkflowField/WorkflowField.jsx +176 -176
- package/src/web/components/WorkflowField/index.js +2 -2
- package/src/web/components/WorkflowField/workflowColors.js +32 -32
- package/src/web/components/auth/DevTenantSelector.jsx +90 -90
- package/src/web/components/auth/ForgotPasswordForm.jsx +94 -94
- package/src/web/components/auth/RegisterForm.jsx +168 -168
- package/src/web/components/auth/ResetPasswordForm.jsx +121 -121
- package/src/web/components/auth/VerifyEmailView.jsx +85 -85
- package/src/web/components/auth/index.js +5 -5
- package/src/web/components/index.js +39 -39
- package/src/web/components/layouts/CardListLayout.jsx +68 -68
- package/src/web/components/layouts/FullscreenLayout.jsx +30 -30
- package/src/web/components/layouts/MobileStackLayout.jsx +28 -28
- package/src/web/components/layouts/WizardLayout.jsx +86 -86
- package/src/web/components/layouts/index.js +4 -4
- package/src/web/components/mobile/Badge.jsx +105 -105
- package/src/web/components/mobile/BadgeThemeEditor.jsx +104 -104
- package/src/web/components/mobile/EmptyState.jsx +30 -30
- package/src/web/components/mobile/QuickActionButton.jsx +77 -77
- package/src/web/components/mobile/ServerAutocomplete.jsx +123 -123
- package/src/web/components/mobile/StarRating.jsx +42 -42
- package/src/web/components/mobile/StatCard.jsx +65 -65
- package/src/web/components/mobile/index.js +7 -7
- package/src/web/extensions/ExtensionRegistry.js +79 -79
- package/src/web/extensions/index.js +7 -7
- package/src/web/hooks/index.js +15 -15
- package/src/web/hooks/useApi.js +76 -76
- package/src/web/hooks/useAuth.js +37 -37
- package/src/web/hooks/useDebouncedSave.js +158 -158
- package/src/web/hooks/useIsMobile.js +14 -14
- package/src/web/hooks/useOfflineQueue.js +99 -99
- package/src/web/hooks/useSelectionModel.js +143 -143
- package/src/web/hooks/useServerAutocomplete.js +146 -146
- package/src/web/hooks/useStore.js +107 -107
- package/src/web/hooks/useSubscription.js +130 -130
- package/src/web/hooks/useTenant.js +39 -39
- package/src/web/hooks/useTenantResolver.js +65 -65
- package/src/web/hooks/useUndoRedo.js +77 -77
- package/src/web/hooks/useViews.js +113 -113
- package/src/web/hooks/useWorkflow.js +190 -190
- package/src/web/index.js +117 -117
- package/src/web/stores/BaseStore.js +439 -439
- package/src/web/stores/StoreContext.jsx +93 -93
- package/src/web/stores/index.js +3 -3
- package/src/web/theme/index.js +3 -3
- package/src/web/theme/mui-theme.js +228 -228
- package/src/web/utils/formatTimeAgo.js +22 -22
- package/src/web/utils/index.js +1 -1
- package/src/web/views/ViewRegistry.js +235 -235
- package/src/web/views/index.js +2 -2
|
@@ -1,426 +1,426 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auth Provider Component
|
|
3
|
-
*
|
|
4
|
-
* Provides authentication context to the application.
|
|
5
|
-
* Handles login, logout, token management, and auth state.
|
|
6
|
-
*/
|
|
7
|
-
import React, { createContext, useState, useCallback, useEffect, useMemo } from 'react';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Auth context - use useAuth hook to access
|
|
11
|
-
*/
|
|
12
|
-
export const AuthContext = createContext(null);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Parse the expiry time from a JWT token
|
|
16
|
-
* @param {string} token - JWT token string
|
|
17
|
-
* @returns {number|null} Expiry time in milliseconds, or null if parsing fails
|
|
18
|
-
*/
|
|
19
|
-
function parseTokenExpiry(token) {
|
|
20
|
-
try {
|
|
21
|
-
const payload = token.split('.')[1];
|
|
22
|
-
const decoded = JSON.parse(atob(payload));
|
|
23
|
-
return decoded.exp ? decoded.exp * 1000 : null;
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Return a user-friendly message for network errors thrown by fetch.
|
|
31
|
-
*/
|
|
32
|
-
function friendlyErrorMessage(err) {
|
|
33
|
-
if (err.name === 'AbortError') {
|
|
34
|
-
return 'Request timed out. Check your connection and try again.';
|
|
35
|
-
}
|
|
36
|
-
if (
|
|
37
|
-
err instanceof TypeError &&
|
|
38
|
-
/Failed to fetch|Load failed|Network request failed/i.test(err.message)
|
|
39
|
-
) {
|
|
40
|
-
return 'Unable to connect to server. Check your connection and try again.';
|
|
41
|
-
}
|
|
42
|
-
return err.message;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Storage keys
|
|
47
|
-
*/
|
|
48
|
-
const TOKEN_KEY = 'avento_token';
|
|
49
|
-
const REFRESH_TOKEN_KEY = 'avento_refresh_token';
|
|
50
|
-
const USER_KEY = 'avento_user';
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Get stored auth data from localStorage
|
|
54
|
-
*/
|
|
55
|
-
function getStoredAuth() {
|
|
56
|
-
try {
|
|
57
|
-
const token = localStorage.getItem(TOKEN_KEY);
|
|
58
|
-
const refreshToken = localStorage.getItem(REFRESH_TOKEN_KEY);
|
|
59
|
-
const userJson = localStorage.getItem(USER_KEY);
|
|
60
|
-
const user = userJson ? JSON.parse(userJson) : null;
|
|
61
|
-
|
|
62
|
-
return { token, refreshToken, user };
|
|
63
|
-
} catch {
|
|
64
|
-
return { token: null, refreshToken: null, user: null };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Store auth data in localStorage
|
|
70
|
-
*/
|
|
71
|
-
function storeAuth(token, refreshToken, user) {
|
|
72
|
-
if (token) {
|
|
73
|
-
localStorage.setItem(TOKEN_KEY, token);
|
|
74
|
-
} else {
|
|
75
|
-
localStorage.removeItem(TOKEN_KEY);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (refreshToken) {
|
|
79
|
-
localStorage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
80
|
-
} else {
|
|
81
|
-
localStorage.removeItem(REFRESH_TOKEN_KEY);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (user) {
|
|
85
|
-
localStorage.setItem(USER_KEY, JSON.stringify(user));
|
|
86
|
-
} else {
|
|
87
|
-
localStorage.removeItem(USER_KEY);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Clear all stored auth data
|
|
93
|
-
*/
|
|
94
|
-
function clearStoredAuth() {
|
|
95
|
-
localStorage.removeItem(TOKEN_KEY);
|
|
96
|
-
localStorage.removeItem(REFRESH_TOKEN_KEY);
|
|
97
|
-
localStorage.removeItem(USER_KEY);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Auth Provider Component
|
|
102
|
-
*
|
|
103
|
-
* @param {Object} props
|
|
104
|
-
* @param {React.ReactNode} props.children - Child components
|
|
105
|
-
* @param {string} props.apiUrl - Base API URL for auth endpoints
|
|
106
|
-
* @param {Function} props.onAuthChange - Callback when auth state changes
|
|
107
|
-
*/
|
|
108
|
-
export function AuthProvider({ children, apiUrl = '/api', onAuthChange, refreshBeforeMs = 5 * 60 * 1000 }) {
|
|
109
|
-
const [user, setUser] = useState(null);
|
|
110
|
-
const [token, setToken] = useState(null);
|
|
111
|
-
const [refreshToken, setRefreshToken] = useState(null);
|
|
112
|
-
const [loading, setLoading] = useState(true);
|
|
113
|
-
const [error, setError] = useState(null);
|
|
114
|
-
const [sessionExpired, setSessionExpired] = useState(false);
|
|
115
|
-
|
|
116
|
-
// Initialize from localStorage on mount
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
const stored = getStoredAuth();
|
|
119
|
-
if (stored.token && stored.user) {
|
|
120
|
-
setToken(stored.token);
|
|
121
|
-
setRefreshToken(stored.refreshToken);
|
|
122
|
-
setUser(stored.user);
|
|
123
|
-
}
|
|
124
|
-
setLoading(false);
|
|
125
|
-
}, []);
|
|
126
|
-
|
|
127
|
-
// Notify on auth changes
|
|
128
|
-
useEffect(() => {
|
|
129
|
-
if (onAuthChange && !loading) {
|
|
130
|
-
onAuthChange({ user, isAuthenticated: !!user });
|
|
131
|
-
}
|
|
132
|
-
}, [user, loading, onAuthChange]);
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Login with email and password
|
|
136
|
-
*/
|
|
137
|
-
const login = useCallback(async (email, password, tenantId) => {
|
|
138
|
-
setLoading(true);
|
|
139
|
-
setError(null);
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
const response = await fetch(`${apiUrl}/auth/login`, {
|
|
143
|
-
method: 'POST',
|
|
144
|
-
headers: { 'Content-Type': 'application/json' },
|
|
145
|
-
body: JSON.stringify({ email, password, tenant_id: tenantId })
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
const data = await response.json();
|
|
149
|
-
|
|
150
|
-
if (!response.ok) {
|
|
151
|
-
throw new Error(data.message || 'Login failed');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
setToken(data.token);
|
|
155
|
-
setRefreshToken(data.refreshToken);
|
|
156
|
-
setUser(data.user);
|
|
157
|
-
storeAuth(data.token, data.refreshToken, data.user);
|
|
158
|
-
|
|
159
|
-
return { success: true, user: data.user, tenant: data.tenant };
|
|
160
|
-
} catch (err) {
|
|
161
|
-
const msg = friendlyErrorMessage(err);
|
|
162
|
-
setError(msg);
|
|
163
|
-
return { success: false, error: msg };
|
|
164
|
-
} finally {
|
|
165
|
-
setLoading(false);
|
|
166
|
-
}
|
|
167
|
-
}, [apiUrl]);
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Set auth state directly from token data (e.g. after guest-join API call)
|
|
171
|
-
*/
|
|
172
|
-
const loginWithToken = useCallback((tokenData) => {
|
|
173
|
-
setToken(tokenData.token);
|
|
174
|
-
setRefreshToken(tokenData.refreshToken);
|
|
175
|
-
setUser(tokenData.user);
|
|
176
|
-
storeAuth(tokenData.token, tokenData.refreshToken, tokenData.user);
|
|
177
|
-
return { success: true };
|
|
178
|
-
}, []);
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Logout - clear all auth state
|
|
182
|
-
*/
|
|
183
|
-
const logout = useCallback(() => {
|
|
184
|
-
setToken(null);
|
|
185
|
-
setRefreshToken(null);
|
|
186
|
-
setUser(null);
|
|
187
|
-
setError(null);
|
|
188
|
-
setSessionExpired(false);
|
|
189
|
-
clearStoredAuth();
|
|
190
|
-
}, []);
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Refresh the access token
|
|
194
|
-
*/
|
|
195
|
-
const refresh = useCallback(async () => {
|
|
196
|
-
if (!refreshToken) {
|
|
197
|
-
return { success: false, error: 'No refresh token' };
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
try {
|
|
201
|
-
const response = await fetch(`${apiUrl}/auth/refresh`, {
|
|
202
|
-
method: 'POST',
|
|
203
|
-
headers: { 'Content-Type': 'application/json' },
|
|
204
|
-
body: JSON.stringify({ refreshToken })
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const data = await response.json();
|
|
208
|
-
|
|
209
|
-
if (!response.ok) {
|
|
210
|
-
throw new Error(data.message || 'Token refresh failed');
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
setToken(data.token);
|
|
214
|
-
const updatedUser = data.user || user;
|
|
215
|
-
if (data.user) setUser(data.user);
|
|
216
|
-
setSessionExpired(false);
|
|
217
|
-
storeAuth(data.token, refreshToken, updatedUser);
|
|
218
|
-
|
|
219
|
-
return { success: true };
|
|
220
|
-
} catch (err) {
|
|
221
|
-
// If refresh fails, signal session expiry (dialog will prompt re-login)
|
|
222
|
-
setSessionExpired(true);
|
|
223
|
-
return { success: false, error: err.message };
|
|
224
|
-
}
|
|
225
|
-
}, [apiUrl, refreshToken, user, logout]);
|
|
226
|
-
|
|
227
|
-
// Auto-refresh timer: refresh the token before it expires
|
|
228
|
-
useEffect(() => {
|
|
229
|
-
if (!token) return;
|
|
230
|
-
|
|
231
|
-
const expiresAt = parseTokenExpiry(token);
|
|
232
|
-
if (!expiresAt) return;
|
|
233
|
-
|
|
234
|
-
const now = Date.now();
|
|
235
|
-
const msUntilRefresh = expiresAt - now - refreshBeforeMs;
|
|
236
|
-
|
|
237
|
-
if (msUntilRefresh <= 0) {
|
|
238
|
-
// Token is already expired or within the refresh window — refresh immediately
|
|
239
|
-
refresh();
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const timerId = setTimeout(() => {
|
|
244
|
-
refresh();
|
|
245
|
-
}, msUntilRefresh);
|
|
246
|
-
|
|
247
|
-
return () => clearTimeout(timerId);
|
|
248
|
-
}, [token, refreshBeforeMs, refresh]);
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Register a new user
|
|
252
|
-
*/
|
|
253
|
-
const register = useCallback(async (userData, tenantId) => {
|
|
254
|
-
setError(null);
|
|
255
|
-
|
|
256
|
-
try {
|
|
257
|
-
const response = await fetch(`${apiUrl}/auth/register`, {
|
|
258
|
-
method: 'POST',
|
|
259
|
-
headers: {
|
|
260
|
-
'Content-Type': 'application/json',
|
|
261
|
-
...(tenantId ? { 'X-Tenant-ID': tenantId } : {})
|
|
262
|
-
},
|
|
263
|
-
body: JSON.stringify(userData)
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
const data = await response.json();
|
|
267
|
-
|
|
268
|
-
if (!response.ok) {
|
|
269
|
-
throw new Error(data.message || 'Registration failed');
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// If auto-login (no email verification required)
|
|
273
|
-
if (data.token) {
|
|
274
|
-
setToken(data.token);
|
|
275
|
-
setRefreshToken(data.refreshToken);
|
|
276
|
-
setUser(data.user);
|
|
277
|
-
storeAuth(data.token, data.refreshToken, data.user);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return { success: true, ...data };
|
|
281
|
-
} catch (err) {
|
|
282
|
-
const msg = friendlyErrorMessage(err);
|
|
283
|
-
setError(msg);
|
|
284
|
-
return { success: false, error: msg };
|
|
285
|
-
}
|
|
286
|
-
}, [apiUrl]);
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Request a password reset email
|
|
290
|
-
*/
|
|
291
|
-
const forgotPassword = useCallback(async (email, tenantId) => {
|
|
292
|
-
setError(null);
|
|
293
|
-
|
|
294
|
-
try {
|
|
295
|
-
const response = await fetch(`${apiUrl}/auth/forgot-password`, {
|
|
296
|
-
method: 'POST',
|
|
297
|
-
headers: {
|
|
298
|
-
'Content-Type': 'application/json',
|
|
299
|
-
...(tenantId ? { 'X-Tenant-ID': tenantId } : {})
|
|
300
|
-
},
|
|
301
|
-
body: JSON.stringify({ email })
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
const data = await response.json();
|
|
305
|
-
|
|
306
|
-
if (!response.ok) {
|
|
307
|
-
throw new Error(data.message || 'Request failed');
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return { success: true, message: data.message };
|
|
311
|
-
} catch (err) {
|
|
312
|
-
const msg = friendlyErrorMessage(err);
|
|
313
|
-
setError(msg);
|
|
314
|
-
return { success: false, error: msg };
|
|
315
|
-
}
|
|
316
|
-
}, [apiUrl]);
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Reset password with token
|
|
320
|
-
*/
|
|
321
|
-
const resetPassword = useCallback(async (token, password) => {
|
|
322
|
-
setError(null);
|
|
323
|
-
|
|
324
|
-
try {
|
|
325
|
-
const response = await fetch(`${apiUrl}/auth/reset-password`, {
|
|
326
|
-
method: 'POST',
|
|
327
|
-
headers: { 'Content-Type': 'application/json' },
|
|
328
|
-
body: JSON.stringify({ token, password })
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
const data = await response.json();
|
|
332
|
-
|
|
333
|
-
if (!response.ok) {
|
|
334
|
-
throw new Error(data.message || 'Reset failed');
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return { success: true, message: data.message };
|
|
338
|
-
} catch (err) {
|
|
339
|
-
const msg = friendlyErrorMessage(err);
|
|
340
|
-
setError(msg);
|
|
341
|
-
return { success: false, error: msg };
|
|
342
|
-
}
|
|
343
|
-
}, [apiUrl]);
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Verify email with token
|
|
347
|
-
*/
|
|
348
|
-
const verifyEmail = useCallback(async (tokenValue) => {
|
|
349
|
-
setError(null);
|
|
350
|
-
|
|
351
|
-
try {
|
|
352
|
-
const response = await fetch(`${apiUrl}/auth/verify-email`, {
|
|
353
|
-
method: 'POST',
|
|
354
|
-
headers: { 'Content-Type': 'application/json' },
|
|
355
|
-
body: JSON.stringify({ token: tokenValue })
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
const data = await response.json();
|
|
359
|
-
|
|
360
|
-
if (!response.ok) {
|
|
361
|
-
throw new Error(data.message || 'Verification failed');
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return { success: true, message: data.message };
|
|
365
|
-
} catch (err) {
|
|
366
|
-
const msg = friendlyErrorMessage(err);
|
|
367
|
-
setError(msg);
|
|
368
|
-
return { success: false, error: msg };
|
|
369
|
-
}
|
|
370
|
-
}, [apiUrl]);
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Check if user has a specific role
|
|
374
|
-
*/
|
|
375
|
-
const hasRole = useCallback((role) => {
|
|
376
|
-
return user?.roles?.includes(role) || false;
|
|
377
|
-
}, [user]);
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Check if user has any of the specified roles
|
|
381
|
-
*/
|
|
382
|
-
const hasAnyRole = useCallback((roles) => {
|
|
383
|
-
if (!user?.roles) return false;
|
|
384
|
-
return roles.some(role => user.roles.includes(role));
|
|
385
|
-
}, [user]);
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Get authorization header for API requests
|
|
389
|
-
*/
|
|
390
|
-
const getAuthHeader = useCallback(() => {
|
|
391
|
-
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
392
|
-
}, [token]);
|
|
393
|
-
|
|
394
|
-
const value = useMemo(() => ({
|
|
395
|
-
// State
|
|
396
|
-
user,
|
|
397
|
-
token,
|
|
398
|
-
isAuthenticated: !!user,
|
|
399
|
-
loading,
|
|
400
|
-
error,
|
|
401
|
-
sessionExpired,
|
|
402
|
-
|
|
403
|
-
// Actions
|
|
404
|
-
login,
|
|
405
|
-
loginWithToken,
|
|
406
|
-
logout,
|
|
407
|
-
refresh,
|
|
408
|
-
register,
|
|
409
|
-
forgotPassword,
|
|
410
|
-
resetPassword,
|
|
411
|
-
verifyEmail,
|
|
412
|
-
|
|
413
|
-
// Helpers
|
|
414
|
-
hasRole,
|
|
415
|
-
hasAnyRole,
|
|
416
|
-
getAuthHeader
|
|
417
|
-
}), [user, token, loading, error, sessionExpired, login, loginWithToken, logout, refresh, register, forgotPassword, resetPassword, verifyEmail, hasRole, hasAnyRole, getAuthHeader]);
|
|
418
|
-
|
|
419
|
-
return (
|
|
420
|
-
<AuthContext.Provider value={value}>
|
|
421
|
-
{children}
|
|
422
|
-
</AuthContext.Provider>
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
export default AuthProvider;
|
|
1
|
+
/**
|
|
2
|
+
* Auth Provider Component
|
|
3
|
+
*
|
|
4
|
+
* Provides authentication context to the application.
|
|
5
|
+
* Handles login, logout, token management, and auth state.
|
|
6
|
+
*/
|
|
7
|
+
import React, { createContext, useState, useCallback, useEffect, useMemo } from 'react';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Auth context - use useAuth hook to access
|
|
11
|
+
*/
|
|
12
|
+
export const AuthContext = createContext(null);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parse the expiry time from a JWT token
|
|
16
|
+
* @param {string} token - JWT token string
|
|
17
|
+
* @returns {number|null} Expiry time in milliseconds, or null if parsing fails
|
|
18
|
+
*/
|
|
19
|
+
function parseTokenExpiry(token) {
|
|
20
|
+
try {
|
|
21
|
+
const payload = token.split('.')[1];
|
|
22
|
+
const decoded = JSON.parse(atob(payload));
|
|
23
|
+
return decoded.exp ? decoded.exp * 1000 : null;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Return a user-friendly message for network errors thrown by fetch.
|
|
31
|
+
*/
|
|
32
|
+
function friendlyErrorMessage(err) {
|
|
33
|
+
if (err.name === 'AbortError') {
|
|
34
|
+
return 'Request timed out. Check your connection and try again.';
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
37
|
+
err instanceof TypeError &&
|
|
38
|
+
/Failed to fetch|Load failed|Network request failed/i.test(err.message)
|
|
39
|
+
) {
|
|
40
|
+
return 'Unable to connect to server. Check your connection and try again.';
|
|
41
|
+
}
|
|
42
|
+
return err.message;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Storage keys
|
|
47
|
+
*/
|
|
48
|
+
const TOKEN_KEY = 'avento_token';
|
|
49
|
+
const REFRESH_TOKEN_KEY = 'avento_refresh_token';
|
|
50
|
+
const USER_KEY = 'avento_user';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get stored auth data from localStorage
|
|
54
|
+
*/
|
|
55
|
+
function getStoredAuth() {
|
|
56
|
+
try {
|
|
57
|
+
const token = localStorage.getItem(TOKEN_KEY);
|
|
58
|
+
const refreshToken = localStorage.getItem(REFRESH_TOKEN_KEY);
|
|
59
|
+
const userJson = localStorage.getItem(USER_KEY);
|
|
60
|
+
const user = userJson ? JSON.parse(userJson) : null;
|
|
61
|
+
|
|
62
|
+
return { token, refreshToken, user };
|
|
63
|
+
} catch {
|
|
64
|
+
return { token: null, refreshToken: null, user: null };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Store auth data in localStorage
|
|
70
|
+
*/
|
|
71
|
+
function storeAuth(token, refreshToken, user) {
|
|
72
|
+
if (token) {
|
|
73
|
+
localStorage.setItem(TOKEN_KEY, token);
|
|
74
|
+
} else {
|
|
75
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (refreshToken) {
|
|
79
|
+
localStorage.setItem(REFRESH_TOKEN_KEY, refreshToken);
|
|
80
|
+
} else {
|
|
81
|
+
localStorage.removeItem(REFRESH_TOKEN_KEY);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (user) {
|
|
85
|
+
localStorage.setItem(USER_KEY, JSON.stringify(user));
|
|
86
|
+
} else {
|
|
87
|
+
localStorage.removeItem(USER_KEY);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Clear all stored auth data
|
|
93
|
+
*/
|
|
94
|
+
function clearStoredAuth() {
|
|
95
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
96
|
+
localStorage.removeItem(REFRESH_TOKEN_KEY);
|
|
97
|
+
localStorage.removeItem(USER_KEY);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Auth Provider Component
|
|
102
|
+
*
|
|
103
|
+
* @param {Object} props
|
|
104
|
+
* @param {React.ReactNode} props.children - Child components
|
|
105
|
+
* @param {string} props.apiUrl - Base API URL for auth endpoints
|
|
106
|
+
* @param {Function} props.onAuthChange - Callback when auth state changes
|
|
107
|
+
*/
|
|
108
|
+
export function AuthProvider({ children, apiUrl = '/api', onAuthChange, refreshBeforeMs = 5 * 60 * 1000 }) {
|
|
109
|
+
const [user, setUser] = useState(null);
|
|
110
|
+
const [token, setToken] = useState(null);
|
|
111
|
+
const [refreshToken, setRefreshToken] = useState(null);
|
|
112
|
+
const [loading, setLoading] = useState(true);
|
|
113
|
+
const [error, setError] = useState(null);
|
|
114
|
+
const [sessionExpired, setSessionExpired] = useState(false);
|
|
115
|
+
|
|
116
|
+
// Initialize from localStorage on mount
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const stored = getStoredAuth();
|
|
119
|
+
if (stored.token && stored.user) {
|
|
120
|
+
setToken(stored.token);
|
|
121
|
+
setRefreshToken(stored.refreshToken);
|
|
122
|
+
setUser(stored.user);
|
|
123
|
+
}
|
|
124
|
+
setLoading(false);
|
|
125
|
+
}, []);
|
|
126
|
+
|
|
127
|
+
// Notify on auth changes
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (onAuthChange && !loading) {
|
|
130
|
+
onAuthChange({ user, isAuthenticated: !!user });
|
|
131
|
+
}
|
|
132
|
+
}, [user, loading, onAuthChange]);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Login with email and password
|
|
136
|
+
*/
|
|
137
|
+
const login = useCallback(async (email, password, tenantId) => {
|
|
138
|
+
setLoading(true);
|
|
139
|
+
setError(null);
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const response = await fetch(`${apiUrl}/auth/login`, {
|
|
143
|
+
method: 'POST',
|
|
144
|
+
headers: { 'Content-Type': 'application/json' },
|
|
145
|
+
body: JSON.stringify({ email, password, tenant_id: tenantId })
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const data = await response.json();
|
|
149
|
+
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
throw new Error(data.message || 'Login failed');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
setToken(data.token);
|
|
155
|
+
setRefreshToken(data.refreshToken);
|
|
156
|
+
setUser(data.user);
|
|
157
|
+
storeAuth(data.token, data.refreshToken, data.user);
|
|
158
|
+
|
|
159
|
+
return { success: true, user: data.user, tenant: data.tenant };
|
|
160
|
+
} catch (err) {
|
|
161
|
+
const msg = friendlyErrorMessage(err);
|
|
162
|
+
setError(msg);
|
|
163
|
+
return { success: false, error: msg };
|
|
164
|
+
} finally {
|
|
165
|
+
setLoading(false);
|
|
166
|
+
}
|
|
167
|
+
}, [apiUrl]);
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Set auth state directly from token data (e.g. after guest-join API call)
|
|
171
|
+
*/
|
|
172
|
+
const loginWithToken = useCallback((tokenData) => {
|
|
173
|
+
setToken(tokenData.token);
|
|
174
|
+
setRefreshToken(tokenData.refreshToken);
|
|
175
|
+
setUser(tokenData.user);
|
|
176
|
+
storeAuth(tokenData.token, tokenData.refreshToken, tokenData.user);
|
|
177
|
+
return { success: true };
|
|
178
|
+
}, []);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Logout - clear all auth state
|
|
182
|
+
*/
|
|
183
|
+
const logout = useCallback(() => {
|
|
184
|
+
setToken(null);
|
|
185
|
+
setRefreshToken(null);
|
|
186
|
+
setUser(null);
|
|
187
|
+
setError(null);
|
|
188
|
+
setSessionExpired(false);
|
|
189
|
+
clearStoredAuth();
|
|
190
|
+
}, []);
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Refresh the access token
|
|
194
|
+
*/
|
|
195
|
+
const refresh = useCallback(async () => {
|
|
196
|
+
if (!refreshToken) {
|
|
197
|
+
return { success: false, error: 'No refresh token' };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
const response = await fetch(`${apiUrl}/auth/refresh`, {
|
|
202
|
+
method: 'POST',
|
|
203
|
+
headers: { 'Content-Type': 'application/json' },
|
|
204
|
+
body: JSON.stringify({ refreshToken })
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const data = await response.json();
|
|
208
|
+
|
|
209
|
+
if (!response.ok) {
|
|
210
|
+
throw new Error(data.message || 'Token refresh failed');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
setToken(data.token);
|
|
214
|
+
const updatedUser = data.user || user;
|
|
215
|
+
if (data.user) setUser(data.user);
|
|
216
|
+
setSessionExpired(false);
|
|
217
|
+
storeAuth(data.token, refreshToken, updatedUser);
|
|
218
|
+
|
|
219
|
+
return { success: true };
|
|
220
|
+
} catch (err) {
|
|
221
|
+
// If refresh fails, signal session expiry (dialog will prompt re-login)
|
|
222
|
+
setSessionExpired(true);
|
|
223
|
+
return { success: false, error: err.message };
|
|
224
|
+
}
|
|
225
|
+
}, [apiUrl, refreshToken, user, logout]);
|
|
226
|
+
|
|
227
|
+
// Auto-refresh timer: refresh the token before it expires
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (!token) return;
|
|
230
|
+
|
|
231
|
+
const expiresAt = parseTokenExpiry(token);
|
|
232
|
+
if (!expiresAt) return;
|
|
233
|
+
|
|
234
|
+
const now = Date.now();
|
|
235
|
+
const msUntilRefresh = expiresAt - now - refreshBeforeMs;
|
|
236
|
+
|
|
237
|
+
if (msUntilRefresh <= 0) {
|
|
238
|
+
// Token is already expired or within the refresh window — refresh immediately
|
|
239
|
+
refresh();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const timerId = setTimeout(() => {
|
|
244
|
+
refresh();
|
|
245
|
+
}, msUntilRefresh);
|
|
246
|
+
|
|
247
|
+
return () => clearTimeout(timerId);
|
|
248
|
+
}, [token, refreshBeforeMs, refresh]);
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Register a new user
|
|
252
|
+
*/
|
|
253
|
+
const register = useCallback(async (userData, tenantId) => {
|
|
254
|
+
setError(null);
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
const response = await fetch(`${apiUrl}/auth/register`, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: {
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
...(tenantId ? { 'X-Tenant-ID': tenantId } : {})
|
|
262
|
+
},
|
|
263
|
+
body: JSON.stringify(userData)
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const data = await response.json();
|
|
267
|
+
|
|
268
|
+
if (!response.ok) {
|
|
269
|
+
throw new Error(data.message || 'Registration failed');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// If auto-login (no email verification required)
|
|
273
|
+
if (data.token) {
|
|
274
|
+
setToken(data.token);
|
|
275
|
+
setRefreshToken(data.refreshToken);
|
|
276
|
+
setUser(data.user);
|
|
277
|
+
storeAuth(data.token, data.refreshToken, data.user);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return { success: true, ...data };
|
|
281
|
+
} catch (err) {
|
|
282
|
+
const msg = friendlyErrorMessage(err);
|
|
283
|
+
setError(msg);
|
|
284
|
+
return { success: false, error: msg };
|
|
285
|
+
}
|
|
286
|
+
}, [apiUrl]);
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Request a password reset email
|
|
290
|
+
*/
|
|
291
|
+
const forgotPassword = useCallback(async (email, tenantId) => {
|
|
292
|
+
setError(null);
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
const response = await fetch(`${apiUrl}/auth/forgot-password`, {
|
|
296
|
+
method: 'POST',
|
|
297
|
+
headers: {
|
|
298
|
+
'Content-Type': 'application/json',
|
|
299
|
+
...(tenantId ? { 'X-Tenant-ID': tenantId } : {})
|
|
300
|
+
},
|
|
301
|
+
body: JSON.stringify({ email })
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const data = await response.json();
|
|
305
|
+
|
|
306
|
+
if (!response.ok) {
|
|
307
|
+
throw new Error(data.message || 'Request failed');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return { success: true, message: data.message };
|
|
311
|
+
} catch (err) {
|
|
312
|
+
const msg = friendlyErrorMessage(err);
|
|
313
|
+
setError(msg);
|
|
314
|
+
return { success: false, error: msg };
|
|
315
|
+
}
|
|
316
|
+
}, [apiUrl]);
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Reset password with token
|
|
320
|
+
*/
|
|
321
|
+
const resetPassword = useCallback(async (token, password) => {
|
|
322
|
+
setError(null);
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
const response = await fetch(`${apiUrl}/auth/reset-password`, {
|
|
326
|
+
method: 'POST',
|
|
327
|
+
headers: { 'Content-Type': 'application/json' },
|
|
328
|
+
body: JSON.stringify({ token, password })
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const data = await response.json();
|
|
332
|
+
|
|
333
|
+
if (!response.ok) {
|
|
334
|
+
throw new Error(data.message || 'Reset failed');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return { success: true, message: data.message };
|
|
338
|
+
} catch (err) {
|
|
339
|
+
const msg = friendlyErrorMessage(err);
|
|
340
|
+
setError(msg);
|
|
341
|
+
return { success: false, error: msg };
|
|
342
|
+
}
|
|
343
|
+
}, [apiUrl]);
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Verify email with token
|
|
347
|
+
*/
|
|
348
|
+
const verifyEmail = useCallback(async (tokenValue) => {
|
|
349
|
+
setError(null);
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
const response = await fetch(`${apiUrl}/auth/verify-email`, {
|
|
353
|
+
method: 'POST',
|
|
354
|
+
headers: { 'Content-Type': 'application/json' },
|
|
355
|
+
body: JSON.stringify({ token: tokenValue })
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const data = await response.json();
|
|
359
|
+
|
|
360
|
+
if (!response.ok) {
|
|
361
|
+
throw new Error(data.message || 'Verification failed');
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return { success: true, message: data.message };
|
|
365
|
+
} catch (err) {
|
|
366
|
+
const msg = friendlyErrorMessage(err);
|
|
367
|
+
setError(msg);
|
|
368
|
+
return { success: false, error: msg };
|
|
369
|
+
}
|
|
370
|
+
}, [apiUrl]);
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Check if user has a specific role
|
|
374
|
+
*/
|
|
375
|
+
const hasRole = useCallback((role) => {
|
|
376
|
+
return user?.roles?.includes(role) || false;
|
|
377
|
+
}, [user]);
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Check if user has any of the specified roles
|
|
381
|
+
*/
|
|
382
|
+
const hasAnyRole = useCallback((roles) => {
|
|
383
|
+
if (!user?.roles) return false;
|
|
384
|
+
return roles.some(role => user.roles.includes(role));
|
|
385
|
+
}, [user]);
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Get authorization header for API requests
|
|
389
|
+
*/
|
|
390
|
+
const getAuthHeader = useCallback(() => {
|
|
391
|
+
return token ? { Authorization: `Bearer ${token}` } : {};
|
|
392
|
+
}, [token]);
|
|
393
|
+
|
|
394
|
+
const value = useMemo(() => ({
|
|
395
|
+
// State
|
|
396
|
+
user,
|
|
397
|
+
token,
|
|
398
|
+
isAuthenticated: !!user,
|
|
399
|
+
loading,
|
|
400
|
+
error,
|
|
401
|
+
sessionExpired,
|
|
402
|
+
|
|
403
|
+
// Actions
|
|
404
|
+
login,
|
|
405
|
+
loginWithToken,
|
|
406
|
+
logout,
|
|
407
|
+
refresh,
|
|
408
|
+
register,
|
|
409
|
+
forgotPassword,
|
|
410
|
+
resetPassword,
|
|
411
|
+
verifyEmail,
|
|
412
|
+
|
|
413
|
+
// Helpers
|
|
414
|
+
hasRole,
|
|
415
|
+
hasAnyRole,
|
|
416
|
+
getAuthHeader
|
|
417
|
+
}), [user, token, loading, error, sessionExpired, login, loginWithToken, logout, refresh, register, forgotPassword, resetPassword, verifyEmail, hasRole, hasAnyRole, getAuthHeader]);
|
|
418
|
+
|
|
419
|
+
return (
|
|
420
|
+
<AuthContext.Provider value={value}>
|
|
421
|
+
{children}
|
|
422
|
+
</AuthContext.Provider>
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export default AuthProvider;
|