@dashadmin/dash-auto-admin 1.3.25 → 1.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -6
- package/dist/DashAutoAdminComponentRegistry.js +64 -1
- package/dist/DashAutoAdminForm.js +137 -1
- package/dist/DashAutoAdminResizableDrawer.js +63 -1
- package/dist/DashAutoAdminSaveButton.js +57 -1
- package/dist/DashAutoCreate.js +102 -1
- package/dist/DashAutoDrawer.js +256 -1
- package/dist/DashAutoEdit.js +99 -1
- package/dist/DashAutoFiltersGenerator.js +193 -1
- package/dist/DashAutoFormGroups.js +118 -1
- package/dist/DashAutoFormLayout.js +68 -1
- package/dist/DashAutoFormMuiTabs.js +291 -1
- package/dist/DashAutoFormTabs.js +132 -1
- package/dist/DashAutoGroup.js +27 -1
- package/dist/DashAutoLayout.js +31 -1
- package/dist/DashAutoList.js +218 -1
- package/dist/DashAutoPostFilterForm.js +47 -1
- package/dist/DashAutoReferenceTab.js +10 -1
- package/dist/DashAutoResource.js +77 -1
- package/dist/DashAutoResourceLayout.js +16 -1
- package/dist/DashAutoShow.js +195 -1
- package/dist/DashAutoTabbedForm.js +244 -1
- package/dist/DashAutoTabbedForm.review.js +221 -1
- package/dist/DashAutoTabs.js +11 -1
- package/dist/DashFilterWrapper.js +62 -1
- package/dist/DashRedirect.js +56 -1
- package/dist/TabbedLayout.js +38 -1
- package/dist/common/DashAutoTitle.js +33 -1
- package/dist/common/components/FabButton.js +59 -1
- package/dist/common/components/TranslatedLabel.js +60 -1
- package/dist/common/settings/Settings.js +196 -1
- package/dist/common/settings/SettingsBarIcons.js +61 -1
- package/dist/context/DashAutoAdminFormContext.js +15 -1
- package/dist/hooks/useAutoAdminLoadingStateMediator.js +36 -1
- package/dist/hooks/useAutoAdminTranslate.js +61 -1
- package/dist/hooks/useHash.js +24 -1
- package/dist/hooks/useLogger.js +20 -1
- package/dist/hooks/useRoutePathPattern.js +20 -1
- package/dist/hooks/useVirtualHash.js +28 -1
- package/dist/index.js +77 -3406
- package/dist/list/DashAutoListActions.js +57 -1
- package/dist/list/DashAutoListDatagridWrapper.js +68 -1
- package/dist/list/DashAutoListDefaultActionsWrapper.js +14 -1
- package/dist/list/DashAutoListFilterFormWithButton.js +80 -1
- package/dist/list/DashAutoListTopToolbar.js +180 -1
- package/dist/mui/AttributeToField.js +576 -1
- package/dist/mui/AttributeToInput.js +630 -1
- package/dist/mui/AutoAdminResizableDrawer.js +63 -1
- package/dist/mui/AutoDataGrid.js +120 -1
- package/dist/mui/AutoReferenceFormTab.js +53 -1
- package/dist/mui/AutoReferenceTab.js +46 -1
- package/dist/mui/AutoTabs.js +19 -1
- package/dist/mui/components/ExtendedPagination.js +34 -1
- package/dist/mui/components/ListStringField.js +25 -1
- package/dist/providers/DashAuthProvider.js +215 -1
- package/dist/providers/DashDataProvider.js +310 -1
- package/dist/providers/index.js +10 -1
- package/dist/react-admin.d.js +0 -0
- package/dist/toolbar/buttons/BottomToolbarButtons.js +65 -1
- package/dist/toolbar/buttons/DashResourceButton.js +181 -1
- package/dist/toolbar/buttons/ListButtons.js +80 -1
- package/dist/toolbar/buttons/ToolbarButtons.js +135 -1
- package/dist/types/ActionCallback.d.js +0 -0
- package/dist/utils/SimpleLogger.js +52 -1
- package/dist/utils/enumToChoices.js +5 -1
- package/dist/utils/evalActionPermission.js +11 -1
- package/dist/utils/groupByTabs.js +21 -1
- package/dist/utils/hashedGroupByTabs.js +12 -1
- package/dist/utils/invertMap.js +12 -1
- package/dist/utils/isClassComponent.js +7 -1
- package/dist/utils/isComponent.js +29 -1
- package/dist/utils/isEnum.js +5 -1
- package/dist/utils/isFC.js +8 -1
- package/dist/utils/replaceParams.js +9 -1
- package/dist/utils/validate.js +19 -1
- package/dist/wrappers/UserAction.js +60 -1
- package/dist/wrappers/index.js +4 -1
- package/package.json +134 -120
- package/src/DashAutoAdminComponentRegistry.tsx +75 -0
- package/src/DashAutoAdminForm.tsx +155 -0
- package/src/DashAutoAdminResizableDrawer.tsx +69 -0
- package/src/DashAutoAdminSaveButton.tsx +116 -0
- package/src/DashAutoCreate.tsx +118 -0
- package/src/DashAutoDrawer.tsx +288 -0
- package/src/DashAutoEdit.tsx +109 -0
- package/src/DashAutoFiltersGenerator.tsx +208 -0
- package/src/DashAutoFormGroups.tsx +146 -0
- package/src/DashAutoFormLayout.tsx.review +113 -0
- package/src/DashAutoFormMuiTabs.tsx +368 -0
- package/src/DashAutoFormTabs.tsx +177 -0
- package/src/DashAutoGroup.tsx +42 -0
- package/src/DashAutoLayout.tsx +57 -0
- package/src/DashAutoList.tsx +237 -0
- package/src/DashAutoPostFilterForm.tsx +35 -0
- package/src/DashAutoReferenceTab.tsx +9 -0
- package/src/DashAutoResource.tsx +85 -0
- package/src/DashAutoResourceLayout.tsx +50 -0
- package/src/DashAutoShow.tsx +200 -0
- package/src/DashAutoTabbedForm.review.tsx +262 -0
- package/src/DashAutoTabbedForm.tsx +324 -0
- package/src/DashAutoTabs.tsx +19 -0
- package/src/DashFilterWrapper.tsx +43 -0
- package/src/DashRedirect.tsx +46 -0
- package/src/TabbedLayout.tsx +29 -0
- package/src/common/DashAutoTitle.tsx +24 -0
- package/src/common/components/FabButton.tsx +40 -0
- package/src/common/components/TranslatedLabel.tsx +81 -0
- package/src/common/settings/Settings.tsx +236 -0
- package/src/common/settings/SettingsBarIcons.tsx +72 -0
- package/src/context/DashAutoAdminFormContext.tsx +31 -0
- package/src/hooks/useAutoAdminLoadingStateMediator.tsx +42 -0
- package/src/hooks/useAutoAdminTranslate.tsx +106 -0
- package/src/hooks/useHash.tsx +27 -0
- package/src/hooks/useLogger.tsx +23 -0
- package/src/hooks/useRoutePathPattern.tsx +24 -0
- package/src/hooks/useVirtualHash.tsx +34 -0
- package/src/index.ts +85 -0
- package/src/interfaces/ICustomResourceSubComponent.ts +11 -0
- package/src/interfaces/IDashApplicationLayoutMainAction.ts +37 -0
- package/src/interfaces/IDashApplicationLayoutMenuItem.ts +24 -0
- package/src/interfaces/IDashAutoAdminAttribute.ts +104 -0
- package/src/interfaces/IDashAutoAdminCustomFieldComponent.ts +18 -0
- package/src/interfaces/IDashAutoAdminFormOptions.ts +22 -0
- package/src/interfaces/IDashAutoAdminListActions.ts +13 -0
- package/src/interfaces/IDashAutoAdminReference.ts +16 -0
- package/src/interfaces/IDashAutoAdminResourceConfig.ts +360 -0
- package/src/interfaces/IDashAutoForm.ts +24 -0
- package/src/interfaces/IDashAutoGridButton.ts +35 -0
- package/src/interfaces/IDashAutoShow.ts +12 -0
- package/src/interfaces/IGroupExtraData.ts +8 -0
- package/src/interfaces/IRecord.ts +7 -0
- package/src/interfaces/IReferenceFilter.ts +55 -0
- package/src/interfaces/IResourceComponent.ts +8 -0
- package/src/interfaces/IToolbarButton.ts +11 -0
- package/src/list/DashAutoListActions.tsx +88 -0
- package/src/list/DashAutoListDatagridWrapper.tsx +74 -0
- package/src/list/DashAutoListDefaultActionsWrapper.tsx +31 -0
- package/src/list/DashAutoListFilterFormWithButton.tsx +93 -0
- package/src/list/DashAutoListTopToolbar.tsx +240 -0
- package/src/mui/AttributeToField.tsx +657 -0
- package/src/mui/AttributeToInput.tsx +728 -0
- package/src/mui/AutoAdminResizableDrawer.tsx +69 -0
- package/src/mui/AutoDataGrid.tsx +127 -0
- package/src/mui/AutoReferenceFormTab.tsx +51 -0
- package/src/mui/AutoReferenceTab.tsx +45 -0
- package/src/mui/AutoTabs.tsx +32 -0
- package/src/mui/components/ExtendedPagination.tsx +23 -0
- package/src/mui/components/ListStringField.tsx +32 -0
- package/src/providers/DashAuthProvider.ts +341 -0
- package/src/providers/DashDataProvider.ts +466 -0
- package/src/providers/index.ts +17 -0
- package/src/toolbar/buttons/BottomToolbarButtons.tsx +59 -0
- package/src/toolbar/buttons/DashResourceButton.tsx +223 -0
- package/src/toolbar/buttons/ListButtons.tsx +137 -0
- package/src/toolbar/buttons/ToolbarButtons.tsx +186 -0
- package/src/utils/SimpleLogger.tsx +46 -0
- package/src/utils/enumToChoices.tsx +3 -0
- package/src/utils/evalActionPermission.tsx +14 -0
- package/src/utils/groupByTabs.tsx +23 -0
- package/src/utils/hashedGroupByTabs.tsx +16 -0
- package/src/utils/invertMap.tsx +10 -0
- package/src/utils/isClassComponent.tsx +9 -0
- package/src/utils/isComponent.tsx +45 -0
- package/src/utils/isEnum.tsx +3 -0
- package/src/utils/isFC.tsx +6 -0
- package/src/utils/replaceParams.tsx +6 -0
- package/src/utils/validate.tsx +24 -0
- package/src/wrappers/UserAction.tsx +67 -0
- package/src/wrappers/index.tsx +1 -0
- /package/{dist → src}/DashAutoAdminSaveButton.tsx.bkup +0 -0
- /package/{dist/DashAutoFormLayout.tsx.review → src/DashAutoFormLayout.tsx} +0 -0
- /package/{dist → src}/DashAutoFormTabs.review +0 -0
- /package/{dist → src}/DashAutoFormTabs.tsx.formcontext.wip +0 -0
- /package/{dist → src}/mui/AttributeToField.tsx.review +0 -0
- /package/{dist → src}/mui/AttributeToInput.tsx.review +0 -0
- /package/{dist → src}/react-admin.d.ts +0 -0
- /package/{dist → src}/types/ActionCallback.d.ts +0 -0
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dash Auth Provider
|
|
3
|
+
*
|
|
4
|
+
* Default authentication provider for Dash applications.
|
|
5
|
+
* This provider handles login, logout, identity, and auth checks.
|
|
6
|
+
*
|
|
7
|
+
* Can be extended or overridden by apps for custom behavior.
|
|
8
|
+
*/
|
|
9
|
+
import type { AuthProvider } from 'react-admin';
|
|
10
|
+
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// TYPES
|
|
13
|
+
// ============================================================================
|
|
14
|
+
|
|
15
|
+
export interface DashAuthProviderConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Axios instance or hook to use for API calls
|
|
18
|
+
*/
|
|
19
|
+
useAxios: () => any;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Storage utility (dashStorage from dash-utils)
|
|
23
|
+
*/
|
|
24
|
+
storage: {
|
|
25
|
+
getItem: (key: string) => string | null;
|
|
26
|
+
setItem: (key: string, value: string) => void;
|
|
27
|
+
removeItem: (key: string) => void;
|
|
28
|
+
clear: () => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Auth persistence service
|
|
33
|
+
*/
|
|
34
|
+
authPersistence: {
|
|
35
|
+
saveAuth: (auth: any) => void;
|
|
36
|
+
getAuth: () => any;
|
|
37
|
+
clearAuth: () => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Function to sync localStorage to device store (for Electron/Capacitor)
|
|
42
|
+
*/
|
|
43
|
+
syncToDeviceStore: () => Promise<void>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Function to sync device store to localStorage
|
|
47
|
+
*/
|
|
48
|
+
syncFromDeviceStore: () => Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Function to trigger auth context events
|
|
52
|
+
*/
|
|
53
|
+
setAuthEvent?: (data: any) => void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Logout utility function
|
|
57
|
+
*/
|
|
58
|
+
logoutFromStorage: (reason?: string) => Promise<void>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get the auth endpoint URL
|
|
62
|
+
*/
|
|
63
|
+
getAuthEndpoint: () => string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Default guest role
|
|
67
|
+
*/
|
|
68
|
+
guestRole?: any;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Enable tenant impersonation
|
|
72
|
+
*/
|
|
73
|
+
enableTenantImpersonation?: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface DashAuthProviderOverrides {
|
|
77
|
+
/**
|
|
78
|
+
* Custom login handler
|
|
79
|
+
*/
|
|
80
|
+
login?: AuthProvider['login'];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Custom logout handler
|
|
84
|
+
*/
|
|
85
|
+
logout?: AuthProvider['logout'];
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Custom getIdentity handler
|
|
89
|
+
*/
|
|
90
|
+
getIdentity?: AuthProvider['getIdentity'];
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Custom checkAuth handler
|
|
94
|
+
*/
|
|
95
|
+
checkAuth?: AuthProvider['checkAuth'];
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Custom checkError handler
|
|
99
|
+
*/
|
|
100
|
+
checkError?: AuthProvider['checkError'];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Custom getPermissions handler (if needed)
|
|
104
|
+
*/
|
|
105
|
+
getPermissions?: AuthProvider['getPermissions'];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// FACTORY FUNCTION
|
|
110
|
+
// ============================================================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Create a Dash auth provider with the given configuration
|
|
114
|
+
*
|
|
115
|
+
* @param config - Configuration for the auth provider
|
|
116
|
+
* @param overrides - Optional method overrides
|
|
117
|
+
* @returns AuthProvider compatible with react-admin
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```tsx
|
|
121
|
+
* import { createDashAuthProvider } from 'dash-auto-admin';
|
|
122
|
+
*
|
|
123
|
+
* const authProvider = createDashAuthProvider({
|
|
124
|
+
* useAxios: () => axiosInstance,
|
|
125
|
+
* storage: dashStorage,
|
|
126
|
+
* authPersistence: AuthPersistenceService,
|
|
127
|
+
* // ... other config
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
export const createDashAuthProvider = (
|
|
132
|
+
config: DashAuthProviderConfig,
|
|
133
|
+
overrides: DashAuthProviderOverrides = {}
|
|
134
|
+
): AuthProvider => {
|
|
135
|
+
const {
|
|
136
|
+
useAxios,
|
|
137
|
+
storage,
|
|
138
|
+
authPersistence,
|
|
139
|
+
syncToDeviceStore,
|
|
140
|
+
syncFromDeviceStore,
|
|
141
|
+
setAuthEvent,
|
|
142
|
+
logoutFromStorage,
|
|
143
|
+
getAuthEndpoint,
|
|
144
|
+
guestRole = { name: 'guest' },
|
|
145
|
+
enableTenantImpersonation = false
|
|
146
|
+
} = config;
|
|
147
|
+
|
|
148
|
+
const defaultProvider: AuthProvider = {
|
|
149
|
+
login: async ({ username, password }) => {
|
|
150
|
+
await syncFromDeviceStore();
|
|
151
|
+
|
|
152
|
+
const axios = useAxios();
|
|
153
|
+
|
|
154
|
+
if (!(username && password)) {
|
|
155
|
+
return Promise.reject();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const loginResponse = await axios.post('/login', {
|
|
160
|
+
email: username,
|
|
161
|
+
password,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (loginResponse.status >= 200 && loginResponse.status <= 299) {
|
|
165
|
+
const redirectTo = loginResponse.data.redirectTo;
|
|
166
|
+
|
|
167
|
+
if (loginResponse.data !== "") {
|
|
168
|
+
storage.setItem('token', loginResponse.data.token);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
try {
|
|
172
|
+
const { data: auth } = await axios.get(getAuthEndpoint());
|
|
173
|
+
|
|
174
|
+
authPersistence.saveAuth(auth);
|
|
175
|
+
|
|
176
|
+
storage.setItem('authenticated', 'true');
|
|
177
|
+
storage.setItem('user', JSON.stringify(auth.user));
|
|
178
|
+
storage.setItem(
|
|
179
|
+
'roles',
|
|
180
|
+
auth.user?.roles
|
|
181
|
+
? JSON.stringify(auth.user.roles)
|
|
182
|
+
: JSON.stringify(guestRole),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
if (setAuthEvent) {
|
|
186
|
+
setAuthEvent({
|
|
187
|
+
authenticated: true,
|
|
188
|
+
user: auth.user,
|
|
189
|
+
auth: auth.auth,
|
|
190
|
+
token: loginResponse.data.token,
|
|
191
|
+
roles: auth.user?.roles
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
await syncToDeviceStore();
|
|
196
|
+
|
|
197
|
+
if (redirectTo) {
|
|
198
|
+
return Promise.resolve({ redirectTo });
|
|
199
|
+
} else {
|
|
200
|
+
return Promise.resolve(auth);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.error('Error getting user auth data');
|
|
205
|
+
await logoutFromStorage("login get auth error");
|
|
206
|
+
return Promise.reject(error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error(error);
|
|
211
|
+
await logoutFromStorage("login error logout");
|
|
212
|
+
return Promise.reject(error);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
await logoutFromStorage("login default error logout");
|
|
216
|
+
return Promise.reject();
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
logout: async (params?: any) => {
|
|
220
|
+
await logoutFromStorage("logout");
|
|
221
|
+
return Promise.resolve("/login");
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
getIdentity: async () => {
|
|
225
|
+
const axios = useAxios();
|
|
226
|
+
const token = storage.getItem('token');
|
|
227
|
+
|
|
228
|
+
if (!token) {
|
|
229
|
+
return Promise.reject('No token present');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
const { data: auth } = await axios.get(getAuthEndpoint());
|
|
234
|
+
|
|
235
|
+
storage.setItem(
|
|
236
|
+
'roles',
|
|
237
|
+
auth.user?.roles
|
|
238
|
+
? JSON.stringify(auth.user.roles)
|
|
239
|
+
: JSON.stringify(guestRole),
|
|
240
|
+
);
|
|
241
|
+
storage.setItem('authenticated', 'true');
|
|
242
|
+
storage.setItem('user', JSON.stringify(auth.user));
|
|
243
|
+
|
|
244
|
+
if (enableTenantImpersonation && auth.user?.tenant_id) {
|
|
245
|
+
storage.setItem('tenant_id', auth.user?.tenant_id);
|
|
246
|
+
storage.setItem('user_id', auth.user?.id);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return await Promise.resolve(auth);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
await logoutFromStorage("get identity error logout");
|
|
252
|
+
return Promise.reject(error);
|
|
253
|
+
} finally {
|
|
254
|
+
await syncToDeviceStore();
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
checkAuth: async () => {
|
|
259
|
+
const isAuthenticated = JSON.parse(storage.getItem('authenticated') || 'false');
|
|
260
|
+
const user = JSON.parse(storage.getItem('user') || 'null');
|
|
261
|
+
|
|
262
|
+
if (isAuthenticated && user?.id) {
|
|
263
|
+
const persistedAuth = authPersistence.getAuth();
|
|
264
|
+
if (persistedAuth) {
|
|
265
|
+
return Promise.resolve();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return Promise.reject();
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
checkError: (error) => {
|
|
273
|
+
const errorStatus = error?.response?.status;
|
|
274
|
+
|
|
275
|
+
window.dispatchEvent(
|
|
276
|
+
new MessageEvent('dash-global-loader', { data: false }),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
if (errorStatus) {
|
|
280
|
+
const errors: any = {};
|
|
281
|
+
switch (errorStatus) {
|
|
282
|
+
case 400:
|
|
283
|
+
case 401:
|
|
284
|
+
case 403:
|
|
285
|
+
case 500:
|
|
286
|
+
window.dispatchEvent(
|
|
287
|
+
new MessageEvent('GlobalError', {
|
|
288
|
+
data: { error: error.response.data || error }
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
return Promise.resolve();
|
|
292
|
+
case 422:
|
|
293
|
+
case 409:
|
|
294
|
+
errors.error =
|
|
295
|
+
'An undefined error occurred, please try again later';
|
|
296
|
+
if (error.response.data?.errors) {
|
|
297
|
+
Object.keys(error.response.data?.errors).forEach((key) => {
|
|
298
|
+
errors[key] = error.response.data?.errors[key].join(' , ');
|
|
299
|
+
});
|
|
300
|
+
} else if (error.response.data?.message) {
|
|
301
|
+
errors.error = error.response.data?.message;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
window.dispatchEvent(
|
|
305
|
+
new MessageEvent('GlobalError', { data: { error: errors } }),
|
|
306
|
+
);
|
|
307
|
+
return Promise.resolve();
|
|
308
|
+
default:
|
|
309
|
+
window.dispatchEvent(
|
|
310
|
+
new MessageEvent('GlobalError', {
|
|
311
|
+
data: { error: error.response.data || error }
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
314
|
+
return Promise.resolve();
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
const _errors: any = {};
|
|
318
|
+
Object.keys(error).forEach((key) => {
|
|
319
|
+
_errors[key] = Array.isArray(error[key])
|
|
320
|
+
? error[key].join(' , ')
|
|
321
|
+
: error[key];
|
|
322
|
+
});
|
|
323
|
+
return Promise.resolve();
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// Merge default provider with overrides
|
|
329
|
+
return {
|
|
330
|
+
...defaultProvider,
|
|
331
|
+
...overrides,
|
|
332
|
+
// Ensure required methods are always present
|
|
333
|
+
login: overrides.login || defaultProvider.login,
|
|
334
|
+
logout: overrides.logout || defaultProvider.logout,
|
|
335
|
+
checkAuth: overrides.checkAuth || defaultProvider.checkAuth,
|
|
336
|
+
checkError: overrides.checkError || defaultProvider.checkError,
|
|
337
|
+
getIdentity: overrides.getIdentity || defaultProvider.getIdentity,
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export default createDashAuthProvider;
|