@nocobase/plugin-auth 0.11.1-alpha.5 → 0.12.0-alpha.2

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.
Files changed (126) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js +1 -1
  3. package/dist/client/index.js +729 -0
  4. package/dist/index.js +20 -0
  5. package/dist/locale/zh-CN.js +20 -0
  6. package/dist/node_modules/cron/LICENSE +8 -0
  7. package/dist/node_modules/cron/lib/cron.js +1 -0
  8. package/dist/node_modules/cron/lib/job.js +215 -0
  9. package/dist/node_modules/cron/lib/time.js +817 -0
  10. package/dist/node_modules/cron/package.json +1 -0
  11. package/{lib → dist}/preset.d.ts +1 -1
  12. package/dist/preset.js +11 -0
  13. package/dist/server/actions/auth.js +22 -0
  14. package/dist/server/actions/authenticators.js +83 -0
  15. package/{src/server/basic-auth.ts → dist/server/basic-auth.js} +41 -42
  16. package/dist/server/collections/authenticators.js +97 -0
  17. package/dist/server/collections/token-blacklist.js +21 -0
  18. package/dist/server/collections/users-authenticators.js +71 -0
  19. package/dist/server/index.js +21 -0
  20. package/dist/server/locale/en-US.js +12 -0
  21. package/dist/server/locale/fr-FR.js +12 -0
  22. package/dist/server/locale/index.js +26 -0
  23. package/dist/server/locale/ja-JP.js +8 -0
  24. package/dist/server/locale/pt-BR.js +12 -0
  25. package/dist/server/locale/zh-CN.js +13 -0
  26. package/dist/server/migrations/20230506152253-basic-authenticator.js +26 -0
  27. package/dist/server/migrations/20230607174500-update-basic.js +29 -0
  28. package/{src/server/model/authenticator.ts → dist/server/model/authenticator.js} +19 -19
  29. package/dist/server/plugin.js +93 -0
  30. package/dist/server/token-blacklist.js +62 -0
  31. package/package.json +17 -28
  32. package/server.d.ts +2 -2
  33. package/server.js +1 -1
  34. package/lib/client/AuthProvider.js +0 -56
  35. package/lib/client/basic/Options.js +0 -51
  36. package/lib/client/basic/SigninPage.js +0 -100
  37. package/lib/client/basic/SignupPage.js +0 -131
  38. package/lib/client/index.js +0 -27
  39. package/lib/client/locale/index.js +0 -19
  40. package/lib/client/settings/Authenticator.js +0 -159
  41. package/lib/client/settings/Options.js +0 -56
  42. package/lib/client/settings/authType.js +0 -27
  43. package/lib/client/settings/schemas/authenticators.js +0 -438
  44. package/lib/index.js +0 -20
  45. package/lib/locale/zh-CN.js +0 -23
  46. package/lib/preset.js +0 -12
  47. package/lib/server/actions/auth.js +0 -51
  48. package/lib/server/actions/authenticators.js +0 -131
  49. package/lib/server/basic-auth.js +0 -183
  50. package/lib/server/collections/authenticators.js +0 -94
  51. package/lib/server/collections/token-blacklist.js +0 -21
  52. package/lib/server/collections/users-authenticators.js +0 -75
  53. package/lib/server/index.js +0 -20
  54. package/lib/server/locale/en-US.js +0 -15
  55. package/lib/server/locale/fr-FR.js +0 -15
  56. package/lib/server/locale/index.js +0 -27
  57. package/lib/server/locale/ja-JP.js +0 -11
  58. package/lib/server/locale/pt-BR.js +0 -15
  59. package/lib/server/locale/zh-CN.js +0 -16
  60. package/lib/server/migrations/20230506152253-basic-authenticator.js +0 -40
  61. package/lib/server/migrations/20230607174500-update-basic.js +0 -43
  62. package/lib/server/model/authenticator.js +0 -72
  63. package/lib/server/plugin.js +0 -129
  64. package/lib/server/token-blacklist.js +0 -82
  65. package/src/client/AuthProvider.tsx +0 -41
  66. package/src/client/basic/Options.tsx +0 -31
  67. package/src/client/basic/SigninPage.tsx +0 -65
  68. package/src/client/basic/SignupPage.tsx +0 -91
  69. package/src/client/index.tsx +0 -10
  70. package/src/client/locale/index.ts +0 -7
  71. package/src/client/settings/Authenticator.tsx +0 -95
  72. package/src/client/settings/Options.tsx +0 -34
  73. package/src/client/settings/authType.ts +0 -18
  74. package/src/client/settings/schemas/authenticators.ts +0 -402
  75. package/src/index.ts +0 -1
  76. package/src/locale/zh-CN.ts +0 -17
  77. package/src/preset.ts +0 -4
  78. package/src/server/__tests__/actions.test.ts +0 -142
  79. package/src/server/__tests__/token-blacklist.test.ts +0 -73
  80. package/src/server/actions/auth.ts +0 -20
  81. package/src/server/actions/authenticators.ts +0 -85
  82. package/src/server/collections/.gitkeep +0 -0
  83. package/src/server/collections/authenticators.ts +0 -98
  84. package/src/server/collections/token-blacklist.ts +0 -19
  85. package/src/server/collections/users-authenticators.ts +0 -73
  86. package/src/server/index.ts +0 -2
  87. package/src/server/locale/en-US.ts +0 -10
  88. package/src/server/locale/fr-FR.ts +0 -10
  89. package/src/server/locale/index.ts +0 -3
  90. package/src/server/locale/ja-JP.ts +0 -4
  91. package/src/server/locale/pt-BR.ts +0 -10
  92. package/src/server/locale/zh-CN.ts +0 -9
  93. package/src/server/migrations/20230506152253-basic-authenticator.ts +0 -22
  94. package/src/server/migrations/20230607174500-update-basic.ts +0 -25
  95. package/src/server/plugin.ts +0 -92
  96. package/src/server/token-blacklist.ts +0 -66
  97. /package/{lib → dist}/client/AuthProvider.d.ts +0 -0
  98. /package/{lib → dist}/client/basic/Options.d.ts +0 -0
  99. /package/{lib → dist}/client/basic/SigninPage.d.ts +0 -0
  100. /package/{lib → dist}/client/basic/SignupPage.d.ts +0 -0
  101. /package/{lib → dist}/client/index.d.ts +0 -0
  102. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  103. /package/{lib → dist}/client/settings/Authenticator.d.ts +0 -0
  104. /package/{lib → dist}/client/settings/Options.d.ts +0 -0
  105. /package/{lib → dist}/client/settings/authType.d.ts +0 -0
  106. /package/{lib → dist}/client/settings/schemas/authenticators.d.ts +0 -0
  107. /package/{lib → dist}/index.d.ts +0 -0
  108. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  109. /package/{lib → dist}/server/actions/auth.d.ts +0 -0
  110. /package/{lib → dist}/server/actions/authenticators.d.ts +0 -0
  111. /package/{lib → dist}/server/basic-auth.d.ts +0 -0
  112. /package/{lib → dist}/server/collections/authenticators.d.ts +0 -0
  113. /package/{lib → dist}/server/collections/token-blacklist.d.ts +0 -0
  114. /package/{lib → dist}/server/collections/users-authenticators.d.ts +0 -0
  115. /package/{lib → dist}/server/index.d.ts +0 -0
  116. /package/{lib → dist}/server/locale/en-US.d.ts +0 -0
  117. /package/{lib → dist}/server/locale/fr-FR.d.ts +0 -0
  118. /package/{lib → dist}/server/locale/index.d.ts +0 -0
  119. /package/{lib → dist}/server/locale/ja-JP.d.ts +0 -0
  120. /package/{lib → dist}/server/locale/pt-BR.d.ts +0 -0
  121. /package/{lib → dist}/server/locale/zh-CN.d.ts +0 -0
  122. /package/{lib → dist}/server/migrations/20230506152253-basic-authenticator.d.ts +0 -0
  123. /package/{lib → dist}/server/migrations/20230607174500-update-basic.d.ts +0 -0
  124. /package/{lib → dist}/server/model/authenticator.d.ts +0 -0
  125. /package/{lib → dist}/server/plugin.d.ts +0 -0
  126. /package/{lib → dist}/server/token-blacklist.d.ts +0 -0
@@ -0,0 +1,729 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@nocobase/client"), require("react"), require("antd"), require("@formily/shared"), require("react-i18next"), require("@ant-design/icons"), require("@formily/react")) : typeof define === "function" && define.amd ? define(["exports", "@nocobase/client", "react", "antd", "@formily/shared", "react-i18next", "@ant-design/icons", "@formily/react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["@nocobase/plugin-auth"] = {}, global["@nocobase/client"], global.react, global.antd, global["@formily/shared"], global["react-i18next"], global["@ant-design/icons"], global["@formily/react"]));
3
+ })(this, function(exports2, client, require$$0, antd, shared, reactI18next, icons, react) {
4
+ "use strict";
5
+ var jsxRuntime = { exports: {} };
6
+ var reactJsxRuntime_production_min = {};
7
+ /**
8
+ * @license React
9
+ * react-jsx-runtime.production.min.js
10
+ *
11
+ * Copyright (c) Facebook, Inc. and its affiliates.
12
+ *
13
+ * This source code is licensed under the MIT license found in the
14
+ * LICENSE file in the root directory of this source tree.
15
+ */
16
+ var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
17
+ function q(c, a, g) {
18
+ var b, d = {}, e = null, h = null;
19
+ void 0 !== g && (e = "" + g);
20
+ void 0 !== a.key && (e = "" + a.key);
21
+ void 0 !== a.ref && (h = a.ref);
22
+ for (b in a)
23
+ m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
24
+ if (c && c.defaultProps)
25
+ for (b in a = c.defaultProps, a)
26
+ void 0 === d[b] && (d[b] = a[b]);
27
+ return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
28
+ }
29
+ reactJsxRuntime_production_min.Fragment = l;
30
+ reactJsxRuntime_production_min.jsx = q;
31
+ reactJsxRuntime_production_min.jsxs = q;
32
+ {
33
+ jsxRuntime.exports = reactJsxRuntime_production_min;
34
+ }
35
+ var jsxRuntimeExports = jsxRuntime.exports;
36
+ const AuthTypeContext = require$$0.createContext({ type: "" });
37
+ const AuthTypesContext = require$$0.createContext({ types: [] });
38
+ const useAuthTypes = () => {
39
+ const { types } = require$$0.useContext(AuthTypesContext);
40
+ return types;
41
+ };
42
+ const collection = {
43
+ name: "authenticators",
44
+ sortable: true,
45
+ fields: [
46
+ {
47
+ name: "id",
48
+ type: "string",
49
+ interface: "id"
50
+ },
51
+ {
52
+ interface: "input",
53
+ type: "string",
54
+ name: "name",
55
+ uiSchema: {
56
+ type: "string",
57
+ title: '{{t("Name")}}',
58
+ "x-component": "Input",
59
+ required: true
60
+ }
61
+ },
62
+ {
63
+ interface: "input",
64
+ type: "string",
65
+ name: "authType",
66
+ uiSchema: {
67
+ type: "string",
68
+ title: '{{t("Auth Type", {ns: "auth"})}}',
69
+ "x-component": "Select",
70
+ required: true
71
+ }
72
+ },
73
+ {
74
+ interface: "input",
75
+ type: "string",
76
+ name: "title",
77
+ uiSchema: {
78
+ type: "string",
79
+ title: '{{t("Title")}}',
80
+ "x-component": "Input"
81
+ }
82
+ },
83
+ {
84
+ interface: "textarea",
85
+ type: "string",
86
+ name: "description",
87
+ uiSchema: {
88
+ type: "string",
89
+ title: '{{t("Description")}}',
90
+ "x-component": "Input"
91
+ }
92
+ },
93
+ {
94
+ type: "boolean",
95
+ name: "enabled",
96
+ uiSchema: {
97
+ type: "boolean",
98
+ title: '{{t("Enabled")}}',
99
+ "x-component": "Checkbox"
100
+ }
101
+ }
102
+ ]
103
+ };
104
+ const createFormSchema = {
105
+ type: "object",
106
+ properties: {
107
+ drawer: {
108
+ type: "void",
109
+ "x-component": "Action.Drawer",
110
+ "x-decorator": "Form",
111
+ "x-decorator-props": {
112
+ useValues(options) {
113
+ const ctx = client.useActionContext();
114
+ const { type: authType } = require$$0.useContext(AuthTypeContext);
115
+ return client.useRequest(
116
+ () => Promise.resolve({
117
+ data: {
118
+ name: `s_${shared.uid()}`,
119
+ authType
120
+ }
121
+ }),
122
+ { ...options, refreshDeps: [ctx.visible] }
123
+ );
124
+ }
125
+ },
126
+ title: '{{t("Add new")}}',
127
+ properties: {
128
+ name: {
129
+ "x-component": "CollectionField",
130
+ "x-decorator": "FormItem"
131
+ },
132
+ authType: {
133
+ "x-component": "CollectionField",
134
+ "x-decorator": "FormItem",
135
+ "x-component-props": {
136
+ options: "{{ types }}"
137
+ }
138
+ },
139
+ title: {
140
+ "x-component": "CollectionField",
141
+ "x-decorator": "FormItem"
142
+ },
143
+ description: {
144
+ "x-component": "CollectionField",
145
+ "x-decorator": "FormItem"
146
+ },
147
+ enabled: {
148
+ "x-component": "CollectionField",
149
+ "x-decorator": "FormItem"
150
+ },
151
+ options: {
152
+ type: "object",
153
+ "x-component": "Options"
154
+ },
155
+ footer: {
156
+ type: "void",
157
+ "x-component": "Action.Drawer.Footer",
158
+ properties: {
159
+ cancel: {
160
+ title: '{{t("Cancel")}}',
161
+ "x-component": "Action",
162
+ "x-component-props": {
163
+ useAction: "{{ cm.useCancelAction }}"
164
+ }
165
+ },
166
+ submit: {
167
+ title: '{{t("Submit")}}',
168
+ "x-component": "Action",
169
+ "x-component-props": {
170
+ type: "primary",
171
+ useAction: "{{ cm.useCreateAction }}"
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ };
180
+ const authenticatorsSchema = {
181
+ type: "void",
182
+ name: "authenticators",
183
+ "x-decorator": "ResourceActionProvider",
184
+ "x-decorator-props": {
185
+ collection,
186
+ resourceName: "authenticators",
187
+ dragSort: true,
188
+ request: {
189
+ resource: "authenticators",
190
+ action: "list",
191
+ params: {
192
+ pageSize: 50,
193
+ sort: "sort",
194
+ appends: []
195
+ }
196
+ }
197
+ },
198
+ "x-component": "CollectionProvider",
199
+ "x-component-props": {
200
+ collection
201
+ },
202
+ properties: {
203
+ actions: {
204
+ type: "void",
205
+ "x-component": "ActionBar",
206
+ "x-component-props": {
207
+ style: {
208
+ marginBottom: 16
209
+ }
210
+ },
211
+ properties: {
212
+ delete: {
213
+ type: "void",
214
+ title: '{{t("Delete")}}',
215
+ "x-component": "Action",
216
+ "x-component-props": {
217
+ useAction: "{{ cm.useBulkDestroyAction }}",
218
+ confirm: {
219
+ title: "{{t('Delete')}}",
220
+ content: "{{t('Are you sure you want to delete it?')}}"
221
+ }
222
+ }
223
+ },
224
+ create: {
225
+ type: "void",
226
+ title: '{{t("Add new")}}',
227
+ "x-component": "AddNew",
228
+ "x-component-props": {
229
+ type: "primary"
230
+ }
231
+ }
232
+ }
233
+ },
234
+ table: {
235
+ type: "void",
236
+ "x-uid": "input",
237
+ "x-component": "Table.Void",
238
+ "x-component-props": {
239
+ rowKey: "id",
240
+ rowSelection: {
241
+ type: "checkbox"
242
+ },
243
+ useDataSource: "{{ cm.useDataSourceFromRAC }}",
244
+ useAction() {
245
+ const api = client.useAPIClient();
246
+ const { t } = reactI18next.useTranslation();
247
+ return {
248
+ async move(from, to) {
249
+ await api.resource("authenticators").move({
250
+ sourceId: from.id,
251
+ targetId: to.id
252
+ });
253
+ antd.message.success(t("Saved successfully"), 0.2);
254
+ }
255
+ };
256
+ }
257
+ },
258
+ properties: {
259
+ id: {
260
+ type: "void",
261
+ "x-decorator": "Table.Column.Decorator",
262
+ "x-component": "Table.Column",
263
+ properties: {
264
+ id: {
265
+ type: "number",
266
+ "x-component": "CollectionField",
267
+ "x-read-pretty": true
268
+ }
269
+ }
270
+ },
271
+ name: {
272
+ type: "void",
273
+ "x-decorator": "Table.Column.Decorator",
274
+ "x-component": "Table.Column",
275
+ properties: {
276
+ name: {
277
+ type: "string",
278
+ "x-component": "CollectionField",
279
+ "x-read-pretty": true
280
+ }
281
+ }
282
+ },
283
+ authType: {
284
+ type: "void",
285
+ "x-decorator": "Table.Column.Decorator",
286
+ "x-component": "Table.Column",
287
+ properties: {
288
+ authType: {
289
+ type: "string",
290
+ "x-component": "CollectionField",
291
+ "x-read-pretty": true
292
+ }
293
+ }
294
+ },
295
+ title: {
296
+ type: "void",
297
+ "x-decorator": "Table.Column.Decorator",
298
+ "x-component": "Table.Column",
299
+ properties: {
300
+ title: {
301
+ type: "string",
302
+ "x-component": "CollectionField",
303
+ "x-read-pretty": true
304
+ }
305
+ }
306
+ },
307
+ description: {
308
+ type: "void",
309
+ "x-decorator": "Table.Column.Decorator",
310
+ "x-component": "Table.Column",
311
+ properties: {
312
+ description: {
313
+ type: "boolean",
314
+ "x-component": "CollectionField",
315
+ "x-read-pretty": true
316
+ }
317
+ }
318
+ },
319
+ enabled: {
320
+ type: "void",
321
+ "x-decorator": "Table.Column.Decorator",
322
+ "x-component": "Table.Column",
323
+ properties: {
324
+ enabled: {
325
+ type: "boolean",
326
+ "x-component": "CollectionField",
327
+ "x-read-pretty": true
328
+ }
329
+ }
330
+ },
331
+ actions: {
332
+ type: "void",
333
+ title: '{{t("Actions")}}',
334
+ "x-component": "Table.Column",
335
+ properties: {
336
+ actions: {
337
+ type: "void",
338
+ "x-component": "Space",
339
+ "x-component-props": {
340
+ split: "|"
341
+ },
342
+ properties: {
343
+ update: {
344
+ type: "void",
345
+ title: '{{t("Configure")}}',
346
+ "x-component": "Action.Link",
347
+ "x-component-props": {
348
+ type: "primary"
349
+ },
350
+ properties: {
351
+ drawer: {
352
+ type: "void",
353
+ "x-component": "Action.Drawer",
354
+ "x-decorator": "Form",
355
+ "x-decorator-props": {
356
+ useValues: "{{ cm.useValuesFromRecord }}"
357
+ },
358
+ title: '{{t("Configure")}}',
359
+ properties: {
360
+ name: {
361
+ "x-component": "CollectionField",
362
+ "x-decorator": "FormItem"
363
+ },
364
+ authType: {
365
+ "x-component": "CollectionField",
366
+ "x-decorator": "FormItem",
367
+ "x-component-props": {
368
+ options: "{{ types }}"
369
+ }
370
+ },
371
+ title: {
372
+ "x-component": "CollectionField",
373
+ "x-decorator": "FormItem"
374
+ },
375
+ description: {
376
+ "x-component": "CollectionField",
377
+ "x-decorator": "FormItem"
378
+ },
379
+ enabled: {
380
+ "x-component": "CollectionField",
381
+ "x-decorator": "FormItem"
382
+ },
383
+ options: {
384
+ type: "object",
385
+ "x-component": "Options"
386
+ },
387
+ footer: {
388
+ type: "void",
389
+ "x-component": "Action.Drawer.Footer",
390
+ properties: {
391
+ cancel: {
392
+ title: '{{t("Cancel")}}',
393
+ "x-component": "Action",
394
+ "x-component-props": {
395
+ useAction: "{{ cm.useCancelAction }}"
396
+ }
397
+ },
398
+ submit: {
399
+ title: '{{t("Submit")}}',
400
+ "x-component": "Action",
401
+ "x-component-props": {
402
+ type: "primary",
403
+ useAction: "{{ cm.useUpdateAction }}"
404
+ }
405
+ }
406
+ }
407
+ }
408
+ }
409
+ }
410
+ }
411
+ },
412
+ delete: {
413
+ type: "void",
414
+ title: '{{ t("Delete") }}',
415
+ "x-component": "Action.Link",
416
+ "x-component-props": {
417
+ confirm: {
418
+ title: "{{t('Delete record')}}",
419
+ content: "{{t('Are you sure you want to delete it?')}}"
420
+ },
421
+ useAction: "{{cm.useDestroyAction}}"
422
+ },
423
+ "x-disabled": "{{ useCanNotDelete() }}"
424
+ }
425
+ }
426
+ }
427
+ }
428
+ }
429
+ }
430
+ }
431
+ }
432
+ };
433
+ const useValuesFromOptions = (options) => {
434
+ const record = client.useRecord();
435
+ const result = client.useRequest(
436
+ () => Promise.resolve({
437
+ data: {
438
+ ...record.options
439
+ }
440
+ }),
441
+ {
442
+ ...options,
443
+ manual: true
444
+ }
445
+ );
446
+ const { run } = result;
447
+ const ctx = client.useActionContext();
448
+ require$$0.useEffect(() => {
449
+ if (ctx.visible) {
450
+ run();
451
+ }
452
+ }, [ctx.visible, run]);
453
+ return result;
454
+ };
455
+ const Options$1 = react.observer(() => {
456
+ const form = react.useForm();
457
+ const record = client.useRecord();
458
+ const component = client.useOptionsComponent(form.values.authType || record.authType);
459
+ return component;
460
+ });
461
+ const useCloseAction = () => {
462
+ const { setVisible } = client.useActionContext();
463
+ return {
464
+ async run() {
465
+ setVisible(false);
466
+ }
467
+ };
468
+ };
469
+ const AddNew = () => {
470
+ const { t } = reactI18next.useTranslation();
471
+ const [visible, setVisible] = require$$0.useState(false);
472
+ const [type, setType] = require$$0.useState("");
473
+ const types = useAuthTypes();
474
+ const items = types.map((item) => ({
475
+ ...item,
476
+ onClick: () => {
477
+ setVisible(true);
478
+ setType(item.value);
479
+ }
480
+ }));
481
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.ActionContextProvider, { value: { visible, setVisible }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(AuthTypeContext.Provider, { value: { type }, children: [
482
+ /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Dropdown, { menu: { items }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(antd.Button, { icon: /* @__PURE__ */ jsxRuntimeExports.jsx(icons.PlusOutlined, {}), type: "primary", children: [
483
+ t("Add new"),
484
+ " ",
485
+ /* @__PURE__ */ jsxRuntimeExports.jsx(icons.DownOutlined, {})
486
+ ] }) }),
487
+ /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { scope: { useCloseAction, types, setType }, schema: createFormSchema })
488
+ ] }) });
489
+ };
490
+ const useCanNotDelete = () => {
491
+ client.useAsyncData();
492
+ return false;
493
+ };
494
+ const Authenticator = () => {
495
+ const [types, setTypes] = require$$0.useState([]);
496
+ const api = client.useAPIClient();
497
+ client.useRequest(
498
+ () => api.resource("authenticators").listTypes().then((res) => {
499
+ var _a;
500
+ const types2 = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.data) || [];
501
+ return types2.map((type) => ({
502
+ key: type,
503
+ label: type,
504
+ value: type
505
+ }));
506
+ }),
507
+ {
508
+ onSuccess: (types2) => {
509
+ setTypes(types2);
510
+ }
511
+ }
512
+ );
513
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(antd.Card, { bordered: false, children: /* @__PURE__ */ jsxRuntimeExports.jsx(AuthTypesContext.Provider, { value: { types }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
514
+ client.SchemaComponent,
515
+ {
516
+ schema: authenticatorsSchema,
517
+ components: { AddNew, Options: Options$1 },
518
+ scope: { types, useValuesFromOptions, useCanNotDelete }
519
+ }
520
+ ) }) });
521
+ };
522
+ const passwordForm = {
523
+ type: "object",
524
+ name: "passwordForm",
525
+ "x-component": "FormV2",
526
+ properties: {
527
+ email: {
528
+ type: "string",
529
+ required: true,
530
+ "x-component": "Input",
531
+ "x-validator": "email",
532
+ "x-decorator": "FormItem",
533
+ "x-component-props": { placeholder: '{{t("Email")}}', style: {} }
534
+ },
535
+ password: {
536
+ type: "string",
537
+ "x-component": "Password",
538
+ required: true,
539
+ "x-decorator": "FormItem",
540
+ "x-component-props": { placeholder: '{{t("Password")}}', style: {} }
541
+ },
542
+ actions: {
543
+ type: "void",
544
+ "x-component": "div",
545
+ properties: {
546
+ submit: {
547
+ title: '{{t("Sign in")}}',
548
+ type: "void",
549
+ "x-component": "Action",
550
+ "x-component-props": {
551
+ htmlType: "submit",
552
+ block: true,
553
+ type: "primary",
554
+ useAction: `{{ useBasicSignIn }}`,
555
+ style: { width: "100%" }
556
+ }
557
+ }
558
+ }
559
+ },
560
+ signup: {
561
+ type: "void",
562
+ "x-component": "Link",
563
+ "x-component-props": {
564
+ to: "{{ signupLink }}"
565
+ },
566
+ "x-content": '{{t("Create an account")}}',
567
+ "x-visible": "{{ allowSignUp }}"
568
+ }
569
+ }
570
+ };
571
+ const SigninPage = (props) => {
572
+ const authenticator = props.authenticator;
573
+ const { authType, name, options } = authenticator;
574
+ const signupPages = require$$0.useContext(client.SignupPageContext);
575
+ const allowSignUp = !!signupPages[authType] && (options == null ? void 0 : options.allowSignup);
576
+ const signupLink = `/signup?authType=${authType}&name=${name}`;
577
+ const useBasicSignIn = () => {
578
+ return client.useSignIn(name);
579
+ };
580
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: passwordForm, scope: { useBasicSignIn, allowSignUp, signupLink } });
581
+ };
582
+ const presetAuthType = "Email/Password";
583
+ const signupPageSchema = {
584
+ type: "object",
585
+ name: shared.uid(),
586
+ "x-component": "FormV2",
587
+ properties: {
588
+ email: {
589
+ type: "string",
590
+ required: true,
591
+ "x-component": "Input",
592
+ "x-validator": "email",
593
+ "x-decorator": "FormItem",
594
+ "x-component-props": { placeholder: '{{t("Email")}}', style: {} }
595
+ },
596
+ password: {
597
+ type: "string",
598
+ required: true,
599
+ "x-component": "Password",
600
+ "x-decorator": "FormItem",
601
+ "x-component-props": { placeholder: '{{t("Password")}}', checkStrength: true, style: {} },
602
+ "x-reactions": [
603
+ {
604
+ dependencies: [".confirm_password"],
605
+ fulfill: {
606
+ state: {
607
+ selfErrors: '{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'
608
+ }
609
+ }
610
+ }
611
+ ]
612
+ },
613
+ confirm_password: {
614
+ type: "string",
615
+ required: true,
616
+ "x-component": "Password",
617
+ "x-decorator": "FormItem",
618
+ "x-component-props": { placeholder: '{{t("Confirm password")}}', style: {} },
619
+ "x-reactions": [
620
+ {
621
+ dependencies: [".password"],
622
+ fulfill: {
623
+ state: {
624
+ selfErrors: '{{$deps[0] && $self.value && $self.value !== $deps[0] ? t("Password mismatch") : ""}}'
625
+ }
626
+ }
627
+ }
628
+ ]
629
+ },
630
+ actions: {
631
+ type: "void",
632
+ "x-component": "div",
633
+ properties: {
634
+ submit: {
635
+ title: '{{t("Sign up")}}',
636
+ type: "void",
637
+ "x-component": "Action",
638
+ "x-component-props": {
639
+ block: true,
640
+ type: "primary",
641
+ htmlType: "submit",
642
+ useAction: "{{ useBasicSignup }}",
643
+ style: { width: "100%" }
644
+ }
645
+ }
646
+ }
647
+ },
648
+ link: {
649
+ type: "void",
650
+ "x-component": "div",
651
+ properties: {
652
+ link: {
653
+ type: "void",
654
+ "x-component": "Link",
655
+ "x-component-props": { to: "/signin" },
656
+ "x-content": '{{t("Log in with an existing account")}}'
657
+ }
658
+ }
659
+ }
660
+ }
661
+ };
662
+ const SignupPage = (props) => {
663
+ const useBasicSignup = () => {
664
+ return client.useSignup({ authenticator: props.name });
665
+ };
666
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: signupPageSchema, scope: { useBasicSignup } });
667
+ };
668
+ const NAMESPACE = "auth";
669
+ function useAuthTranslation() {
670
+ return reactI18next.useTranslation(NAMESPACE);
671
+ }
672
+ const Options = () => {
673
+ const { t } = useAuthTranslation();
674
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
675
+ client.SchemaComponent,
676
+ {
677
+ scope: { t },
678
+ schema: {
679
+ type: "object",
680
+ properties: {
681
+ public: {
682
+ type: "object",
683
+ properties: {
684
+ allowSignup: {
685
+ "x-decorator": "FormItem",
686
+ type: "boolean",
687
+ title: '{{t("Allow to sign up")}}',
688
+ "x-component": "Checkbox",
689
+ "x-component-props": {
690
+ defaultChecked: true
691
+ }
692
+ }
693
+ }
694
+ }
695
+ }
696
+ }
697
+ }
698
+ );
699
+ };
700
+ const AuthProvider = (props) => {
701
+ const { t } = useAuthTranslation();
702
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
703
+ client.SettingsCenterProvider,
704
+ {
705
+ settings: {
706
+ auth: {
707
+ title: t("Authentication"),
708
+ icon: "LoginOutlined",
709
+ tabs: {
710
+ authenticators: {
711
+ title: t("Authenticators"),
712
+ component: () => /* @__PURE__ */ jsxRuntimeExports.jsx(Authenticator, {})
713
+ }
714
+ }
715
+ }
716
+ },
717
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.OptionsComponentProvider, { authType: presetAuthType, component: Options, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.SigninPageProvider, { authType: presetAuthType, tabTitle: t("Sign in via email"), component: SigninPage, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.SignupPageProvider, { authType: presetAuthType, component: SignupPage, children: props.children }) }) })
718
+ }
719
+ );
720
+ };
721
+ class AuthPlugin extends client.Plugin {
722
+ async load() {
723
+ this.app.use(AuthProvider);
724
+ }
725
+ }
726
+ exports2.AuthPlugin = AuthPlugin;
727
+ exports2.default = AuthPlugin;
728
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
729
+ });