@nocobase/plugin-auth 0.12.0-alpha.5 → 0.13.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.
@@ -54,7 +54,7 @@
54
54
  name: "name",
55
55
  uiSchema: {
56
56
  type: "string",
57
- title: '{{t("Name")}}',
57
+ title: '{{t("Auth UID")}}',
58
58
  "x-component": "Input",
59
59
  required: true
60
60
  }
@@ -65,8 +65,9 @@
65
65
  name: "authType",
66
66
  uiSchema: {
67
67
  type: "string",
68
- title: '{{t("Auth Type", {ns: "auth"})}}',
68
+ title: '{{t("Auth Type")}}',
69
69
  "x-component": "Select",
70
+ dataSource: "{{ types }}",
70
71
  required: true
71
72
  }
72
73
  },
@@ -281,14 +282,16 @@
281
282
  }
282
283
  },
283
284
  authType: {
285
+ title: '{{t("Auth Type")}}',
284
286
  type: "void",
285
287
  "x-decorator": "Table.Column.Decorator",
286
288
  "x-component": "Table.Column",
287
289
  properties: {
288
290
  authType: {
289
291
  type: "string",
290
- "x-component": "CollectionField",
291
- "x-read-pretty": true
292
+ "x-component": "Select",
293
+ "x-read-pretty": true,
294
+ enum: "{{ types }}"
292
295
  }
293
296
  }
294
297
  },
@@ -458,6 +461,10 @@
458
461
  const component = client.useOptionsComponent(form.values.authType || record.authType);
459
462
  return component;
460
463
  });
464
+ const NAMESPACE = "auth";
465
+ function useAuthTranslation() {
466
+ return reactI18next.useTranslation(NAMESPACE);
467
+ }
461
468
  const useCloseAction = () => {
462
469
  const { setVisible } = client.useActionContext();
463
470
  return {
@@ -492,6 +499,7 @@
492
499
  return false;
493
500
  };
494
501
  const Authenticator = () => {
502
+ const { t } = useAuthTranslation();
495
503
  const [types, setTypes] = require$$0.useState([]);
496
504
  const api = client.useAPIClient();
497
505
  client.useRequest(
@@ -499,9 +507,9 @@
499
507
  var _a;
500
508
  const types2 = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.data) || [];
501
509
  return types2.map((type) => ({
502
- key: type,
503
- label: type,
504
- value: type
510
+ key: type.name,
511
+ label: t(type.title || type.name),
512
+ value: type.name
505
513
  }));
506
514
  }),
507
515
  {
@@ -515,7 +523,7 @@
515
523
  {
516
524
  schema: authenticatorsSchema,
517
525
  components: { AddNew, Options: Options$1 },
518
- scope: { types, useValuesFromOptions, useCanNotDelete }
526
+ scope: { types, useValuesFromOptions, useCanNotDelete, t }
519
527
  }
520
528
  ) }) });
521
529
  };
@@ -524,13 +532,23 @@
524
532
  name: "passwordForm",
525
533
  "x-component": "FormV2",
526
534
  properties: {
527
- email: {
535
+ account: {
528
536
  type: "string",
529
- required: true,
530
537
  "x-component": "Input",
531
- "x-validator": "email",
538
+ "x-validator": `{{(value) => {
539
+ if (!value) {
540
+ return t("Please enter your username or email");
541
+ }
542
+ if (value.includes('@')) {
543
+ if (!/^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$/.test(value)) {
544
+ return t("Please enter a valid email");
545
+ }
546
+ } else {
547
+ return /^[^@.<>"'/]{2,16}$/.test(value) || t("Please enter a valid username");
548
+ }
549
+ }}}`,
532
550
  "x-decorator": "FormItem",
533
- "x-component-props": { placeholder: '{{t("Email")}}', style: {} }
551
+ "x-component-props": { placeholder: '{{t("Username/Email")}}', style: {} }
534
552
  },
535
553
  password: {
536
554
  type: "string",
@@ -569,6 +587,7 @@
569
587
  }
570
588
  };
571
589
  const SigninPage = (props) => {
590
+ const { t } = useAuthTranslation();
572
591
  const authenticator = props.authenticator;
573
592
  const { authType, name, options } = authenticator;
574
593
  const signupPages = require$$0.useContext(client.SignupPageContext);
@@ -577,7 +596,7 @@
577
596
  const useBasicSignIn = () => {
578
597
  return client.useSignIn(name);
579
598
  };
580
- return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: passwordForm, scope: { useBasicSignIn, allowSignUp, signupLink } });
599
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: passwordForm, scope: { useBasicSignIn, allowSignUp, signupLink, t } });
581
600
  };
582
601
  const presetAuthType = "Email/Password";
583
602
  const signupPageSchema = {
@@ -585,13 +604,13 @@
585
604
  name: shared.uid(),
586
605
  "x-component": "FormV2",
587
606
  properties: {
588
- email: {
607
+ username: {
589
608
  type: "string",
590
609
  required: true,
591
610
  "x-component": "Input",
592
- "x-validator": "email",
611
+ "x-validator": { username: true },
593
612
  "x-decorator": "FormItem",
594
- "x-component-props": { placeholder: '{{t("Email")}}', style: {} }
613
+ "x-component-props": { placeholder: '{{t("Username")}}', style: {} }
595
614
  },
596
615
  password: {
597
616
  type: "string",
@@ -660,21 +679,19 @@
660
679
  }
661
680
  };
662
681
  const SignupPage = (props) => {
682
+ const { t } = useAuthTranslation();
663
683
  const useBasicSignup = () => {
664
684
  return client.useSignup({ authenticator: props.name });
665
685
  };
666
- return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: signupPageSchema, scope: { useBasicSignup } });
686
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(client.SchemaComponent, { schema: signupPageSchema, scope: { useBasicSignup, t } });
667
687
  };
668
- const NAMESPACE = "auth";
669
- function useAuthTranslation() {
670
- return reactI18next.useTranslation(NAMESPACE);
671
- }
672
688
  const Options = () => {
673
689
  const { t } = useAuthTranslation();
674
690
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
675
691
  client.SchemaComponent,
676
692
  {
677
693
  scope: { t },
694
+ components: { Alert: antd.Alert },
678
695
  schema: {
679
696
  type: "object",
680
697
  properties: {
@@ -691,6 +708,14 @@
691
708
  }
692
709
  }
693
710
  }
711
+ },
712
+ notice: {
713
+ type: "void",
714
+ "x-component": "Alert",
715
+ "x-component-props": {
716
+ showIcon: true,
717
+ message: '{{t("The authentication allows users to sign in via username or email.")}}'
718
+ }
694
719
  }
695
720
  }
696
721
  }
@@ -714,7 +739,7 @@
714
739
  }
715
740
  }
716
741
  },
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 }) }) })
742
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.OptionsComponentProvider, { authType: presetAuthType, component: Options, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.SigninPageProvider, { authType: presetAuthType, tabTitle: t("Sign in via password"), component: SigninPage, children: /* @__PURE__ */ jsxRuntimeExports.jsx(client.SignupPageProvider, { authType: presetAuthType, component: SignupPage, children: props.children }) }) })
718
743
  }
719
744
  );
720
745
  };
@@ -3,14 +3,22 @@ declare const locale: {
3
3
  Authenticators: string;
4
4
  Authentication: string;
5
5
  'Sign in via email': string;
6
+ 'Sign in via password': string;
6
7
  'Not allowed to sign up': string;
7
8
  'Allow to sign up': string;
8
- 'The email is incorrect, please re-enter': string;
9
- 'Please fill in your email address': string;
9
+ 'The username or email is incorrect, please re-enter': string;
10
10
  'The password is incorrect, please re-enter': string;
11
11
  'Not a valid cellphone number, please re-enter': string;
12
12
  'The phone number has been registered, please login directly': string;
13
13
  'The phone number is not registered, please register first': string;
14
14
  'Please keep and enable at least one authenticator': string;
15
+ 'Allow to sign in with': string;
16
+ 'Please enter a valid username': string;
17
+ 'Please enter a valid email': string;
18
+ 'Please enter your username or email': string;
19
+ SMS: string;
20
+ 'Username/Email': string;
21
+ 'Auth UID': string;
22
+ 'The authentication allows users to sign in via username or email.': string;
15
23
  };
16
24
  export default locale;
@@ -5,15 +5,23 @@ const locale = {
5
5
  Authenticators: "\u8BA4\u8BC1\u5668",
6
6
  Authentication: "\u7528\u6237\u8BA4\u8BC1",
7
7
  "Sign in via email": "\u90AE\u7BB1\u767B\u5F55",
8
+ "Sign in via password": "\u5BC6\u7801\u767B\u5F55",
8
9
  "Not allowed to sign up": "\u7981\u6B62\u6CE8\u518C",
9
10
  "Allow to sign up": "\u5141\u8BB8\u6CE8\u518C",
10
- "The email is incorrect, please re-enter": "\u90AE\u7BB1\u6709\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
11
- "Please fill in your email address": "\u8BF7\u586B\u5199\u90AE\u7BB1",
11
+ "The username or email is incorrect, please re-enter": "\u7528\u6237\u540D\u6216\u90AE\u7BB1\u6709\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
12
12
  "The password is incorrect, please re-enter": "\u5BC6\u7801\u6709\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
13
13
  "Not a valid cellphone number, please re-enter": "\u4E0D\u662F\u6709\u6548\u7684\u624B\u673A\u53F7\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
14
14
  "The phone number has been registered, please login directly": "\u624B\u673A\u53F7\u5DF2\u6CE8\u518C\uFF0C\u8BF7\u76F4\u63A5\u767B\u5F55",
15
15
  "The phone number is not registered, please register first": "\u624B\u673A\u53F7\u672A\u6CE8\u518C\uFF0C\u8BF7\u5148\u6CE8\u518C",
16
- "Please keep and enable at least one authenticator": "\u8BF7\u81F3\u5C11\u4FDD\u7559\u5E76\u542F\u7528\u4E00\u4E2A\u8BA4\u8BC1\u5668"
16
+ "Please keep and enable at least one authenticator": "\u8BF7\u81F3\u5C11\u4FDD\u7559\u5E76\u542F\u7528\u4E00\u4E2A\u8BA4\u8BC1\u5668",
17
+ "Allow to sign in with": "\u5141\u8BB8\u4F7F\u7528\u4EE5\u4E0B\u65B9\u5F0F\u767B\u5F55",
18
+ "Please enter a valid username": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u7528\u6237\u540D",
19
+ "Please enter a valid email": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u90AE\u7BB1",
20
+ "Please enter your username or email": "\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1",
21
+ SMS: "\u77ED\u4FE1",
22
+ "Username/Email": "\u7528\u6237\u540D/\u90AE\u7BB1",
23
+ "Auth UID": "\u8BA4\u8BC1\u6807\u8BC6",
24
+ "The authentication allows users to sign in via username or email.": "\u8BE5\u8BA4\u8BC1\u65B9\u5F0F\u652F\u6301\u7528\u6237\u901A\u8FC7\u7528\u6237\u540D\u6216\u90AE\u7BB1\u767B\u5F55\u3002"
17
25
  };
18
26
  var zh_CN_default = locale;
19
27
 
@@ -1 +1 @@
1
- {"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-08-18T08:35:43.796Z"}
1
+ {"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-08-24T16:00:17.118Z"}
@@ -15,20 +15,29 @@ class BasicAuth extends auth.BaseAuth {
15
15
  }
16
16
  async validate() {
17
17
  const ctx = this.ctx;
18
- const { uniqueField = "email", values } = ctx.action.params;
19
- if (!values[uniqueField]) {
20
- ctx.throw(400, ctx.t("Please fill in your email address", { ns: preset.namespace }));
18
+ const {
19
+ values: {
20
+ account,
21
+ // Username or email
22
+ email,
23
+ // Old parameter, compatible with old api
24
+ password
25
+ }
26
+ } = ctx.action.params;
27
+ if (!account && !email) {
28
+ ctx.throw(400, ctx.t("Please enter your username or email", { ns: preset.namespace }));
21
29
  }
30
+ const filter = email ? { email } : {
31
+ $or: [{ username: account }, { email: account }]
32
+ };
22
33
  const user = await this.userRepository.findOne({
23
- where: {
24
- [uniqueField]: values[uniqueField]
25
- }
34
+ filter
26
35
  });
27
36
  if (!user) {
28
- ctx.throw(401, ctx.t("The email is incorrect, please re-enter", { ns: preset.namespace }));
37
+ ctx.throw(401, ctx.t("The username or email is incorrect, please re-enter", { ns: preset.namespace }));
29
38
  }
30
39
  const field = this.userCollection.getField("password");
31
- const valid = await field.verify(values.password, user.password);
40
+ const valid = await field.verify(password, user.password);
32
41
  if (!valid) {
33
42
  ctx.throw(401, ctx.t("The password is incorrect, please re-enter", { ns: preset.namespace }));
34
43
  }
@@ -43,6 +52,10 @@ class BasicAuth extends auth.BaseAuth {
43
52
  }
44
53
  const User = ctx.db.getRepository("users");
45
54
  const { values } = ctx.action.params;
55
+ const { username } = values;
56
+ if (!/^[^@.<>"'/]{2,16}$/.test(username)) {
57
+ ctx.throw(400, ctx.t("Please enter a valid username", { ns: preset.namespace }));
58
+ }
46
59
  const user = await User.create({ values });
47
60
  return user;
48
61
  }
@@ -1,10 +1,11 @@
1
1
  declare const _default: {
2
- 'The email is incorrect, please re-enter': string;
3
- 'Please fill in your email address': string;
2
+ 'The username or email is incorrect, please re-enter': string;
4
3
  'The password is incorrect, please re-enter': string;
5
4
  'Not a valid cellphone number, please re-enter': string;
6
5
  'The phone number has been registered, please login directly': string;
7
6
  'The phone number is not registered, please register first': string;
8
7
  'Please keep and enable at least one authenticator': string;
8
+ 'Please enter your username or email': string;
9
+ 'Please enter a valid username': string;
9
10
  };
10
11
  export default _default;
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  var zh_CN_default = {
4
- "The email is incorrect, please re-enter": "\u90AE\u7BB1\u6709\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
5
- "Please fill in your email address": "\u8BF7\u586B\u5199\u90AE\u7BB1",
4
+ "The username or email is incorrect, please re-enter": "\u7528\u6237\u540D\u6216\u90AE\u7BB1\u6709\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
6
5
  "The password is incorrect, please re-enter": "\u5BC6\u7801\u6709\u8BEF\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
7
6
  "Not a valid cellphone number, please re-enter": "\u4E0D\u662F\u6709\u6548\u7684\u624B\u673A\u53F7\uFF0C\u8BF7\u91CD\u65B0\u8F93\u5165",
8
7
  "The phone number has been registered, please login directly": "\u624B\u673A\u53F7\u5DF2\u6CE8\u518C\uFF0C\u8BF7\u76F4\u63A5\u767B\u5F55",
9
8
  "The phone number is not registered, please register first": "\u624B\u673A\u53F7\u672A\u6CE8\u518C\uFF0C\u8BF7\u5148\u6CE8\u518C",
10
- "Please keep and enable at least one authenticator": "\u8BF7\u81F3\u5C11\u4FDD\u7559\u5E76\u542F\u7528\u4E00\u4E2A\u8BA4\u8BC1\u5668"
9
+ "Please keep and enable at least one authenticator": "\u8BF7\u81F3\u5C11\u4FDD\u7559\u5E76\u542F\u7528\u4E00\u4E2A\u8BA4\u8BC1\u5668",
10
+ "Please enter your username or email": "\u8BF7\u8F93\u5165\u7528\u6237\u540D\u6216\u90AE\u7BB1",
11
+ "Please enter a valid username": "\u8BF7\u8F93\u5165\u6709\u6548\u7684\u7528\u6237\u540D"
11
12
  };
12
13
 
13
14
  module.exports = zh_CN_default;
@@ -14,7 +14,7 @@ class AddBasicAuthMigration extends server.Migration {
14
14
  values: {
15
15
  name: preset.presetAuthenticator,
16
16
  authType: preset.presetAuthType,
17
- description: "Sign in with email and password.",
17
+ description: "Sign in with username/email.",
18
18
  enabled: true
19
19
  }
20
20
  });
@@ -48,7 +48,8 @@ class AuthPlugin extends server.Plugin {
48
48
  this.app.authManager.setTokenBlacklistService(new tokenBlacklist.TokenBlacklistService(this));
49
49
  }
50
50
  this.app.authManager.registerTypes(preset.presetAuthType, {
51
- auth: basicAuth.BasicAuth
51
+ auth: basicAuth.BasicAuth,
52
+ title: "Password"
52
53
  });
53
54
  Object.entries(authActions__default.default).forEach(
54
55
  ([action, handler]) => this.app.resourcer.registerAction(`auth:${action}`, handler)
@@ -74,7 +75,7 @@ class AuthPlugin extends server.Plugin {
74
75
  values: {
75
76
  name: preset.presetAuthenticator,
76
77
  authType: preset.presetAuthType,
77
- description: "Sign in with email and password.",
78
+ description: "Sign in with username/email.",
78
79
  enabled: true,
79
80
  options: {
80
81
  public: {
@@ -8,8 +8,7 @@ export declare class TokenBlacklistService implements ITokenBlacklistService {
8
8
  cronJob: CronJob;
9
9
  constructor(plugin: AuthPlugin);
10
10
  get app(): import("@nocobase/server").default<import("@nocobase/server").DefaultState, import("@nocobase/server").DefaultContext>;
11
- createCronJob(): CronJob;
12
11
  has(token: string): Promise<boolean>;
13
12
  add(values: any): Promise<[import("@nocobase/database").Model<any, any>, boolean]>;
14
- deleteByExpiration(): Promise<any>;
13
+ deleteExpiredTokens(): Promise<any>;
15
14
  }
@@ -1,38 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var cron = require('cron');
4
-
5
3
  class TokenBlacklistService {
6
4
  constructor(plugin) {
7
5
  this.plugin = plugin;
8
6
  this.repo = plugin.db.getRepository("tokenBlacklist");
9
- this.cronJob = this.createCronJob();
10
7
  }
11
8
  repo;
12
9
  cronJob;
13
10
  get app() {
14
11
  return this.plugin.app;
15
12
  }
16
- createCronJob() {
17
- const cronJob = new cron.CronJob(
18
- // every day at 03:00
19
- "0 3 * * *",
20
- //
21
- async () => {
22
- this.app.logger.info(`${this.plugin.name}: Start delete expired blacklist token`);
23
- await this.deleteByExpiration();
24
- this.app.logger.info(`${this.plugin.name}: End delete expired blacklist token`);
25
- },
26
- null
27
- );
28
- this.app.once("beforeStart", () => {
29
- cronJob.start();
30
- });
31
- this.app.once("beforeStop", () => {
32
- cronJob.stop();
33
- });
34
- return cronJob;
35
- }
36
13
  async has(token) {
37
14
  return !!await this.repo.findOne({
38
15
  filter: {
@@ -41,6 +18,7 @@ class TokenBlacklistService {
41
18
  });
42
19
  }
43
20
  async add(values) {
21
+ await this.deleteExpiredTokens();
44
22
  return this.repo.model.findOrCreate({
45
23
  defaults: values,
46
24
  where: {
@@ -48,7 +26,7 @@ class TokenBlacklistService {
48
26
  }
49
27
  });
50
28
  }
51
- async deleteByExpiration() {
29
+ async deleteExpiredTokens() {
52
30
  return this.repo.destroy({
53
31
  filter: {
54
32
  expiration: {