@wecode-team/cms-supabase-api 0.1.48 → 0.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/auth.d.ts +30 -0
- package/dist/index.esm.js +361 -213
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +361 -213
- package/dist/index.js.map +1 -1
- package/dist/utils/admin-registry.d.ts +5 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var supabaseJs = require('@supabase/supabase-js');
|
|
4
|
+
var emailVerify = require('@wecode-team/email-verify');
|
|
4
5
|
var jwt = require('jsonwebtoken');
|
|
5
6
|
var bcrypt = require('bcryptjs');
|
|
6
7
|
|
|
@@ -1033,8 +1034,8 @@ function _defineProperty(e, r, t) {
|
|
|
1033
1034
|
}) : e[r] = t, e;
|
|
1034
1035
|
}
|
|
1035
1036
|
|
|
1036
|
-
function ownKeys$
|
|
1037
|
-
function _objectSpread$
|
|
1037
|
+
function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
1038
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
1038
1039
|
function _createForOfIteratorHelper$2(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$3(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
1039
1040
|
function _unsupportedIterableToArray$3(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$3(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$3(r, a) : void 0; } }
|
|
1040
1041
|
function _arrayLikeToArray$3(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -2090,7 +2091,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2090
2091
|
throw error;
|
|
2091
2092
|
case 2:
|
|
2092
2093
|
return _context14.abrupt("return", (data || []).map(function (item) {
|
|
2093
|
-
return _objectSpread$
|
|
2094
|
+
return _objectSpread$3({
|
|
2094
2095
|
id: item.id,
|
|
2095
2096
|
label: item[displayField] || "ID: ".concat(item.id)
|
|
2096
2097
|
}, item);
|
|
@@ -2203,8 +2204,8 @@ function getDynamicTableService() {
|
|
|
2203
2204
|
return defaultService$1;
|
|
2204
2205
|
}
|
|
2205
2206
|
|
|
2206
|
-
function ownKeys$
|
|
2207
|
-
function _objectSpread$
|
|
2207
|
+
function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2208
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2208
2209
|
var AuthService = /*#__PURE__*/function () {
|
|
2209
2210
|
function AuthService() {
|
|
2210
2211
|
_classCallCheck(this, AuthService);
|
|
@@ -2381,7 +2382,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2381
2382
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
2382
2383
|
while (1) switch (_context4.prev = _context4.next) {
|
|
2383
2384
|
case 0:
|
|
2384
|
-
finalUserData = _objectSpread$
|
|
2385
|
+
finalUserData = _objectSpread$2({
|
|
2385
2386
|
tableName: this.defaultTableName
|
|
2386
2387
|
}, userData);
|
|
2387
2388
|
_context4.prev = 1;
|
|
@@ -2439,7 +2440,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2439
2440
|
case 0:
|
|
2440
2441
|
updateData = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
2441
2442
|
// 设置默认值
|
|
2442
|
-
finalUpdateData = _objectSpread$
|
|
2443
|
+
finalUpdateData = _objectSpread$2({
|
|
2443
2444
|
tableName: this.defaultTableName
|
|
2444
2445
|
}, updateData);
|
|
2445
2446
|
_context5.prev = 1;
|
|
@@ -2847,8 +2848,8 @@ function _toConsumableArray(r) {
|
|
|
2847
2848
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$2(r) || _nonIterableSpread();
|
|
2848
2849
|
}
|
|
2849
2850
|
|
|
2850
|
-
function ownKeys$
|
|
2851
|
-
function _objectSpread$
|
|
2851
|
+
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2852
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2852
2853
|
function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
2853
2854
|
function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2854
2855
|
// src/error.ts
|
|
@@ -3376,7 +3377,7 @@ var DEFAULT_LIMITS = {
|
|
|
3376
3377
|
other: 10 * 1024 * 1024
|
|
3377
3378
|
};
|
|
3378
3379
|
function getSizeLimit(fileName, limits) {
|
|
3379
|
-
var merged = _objectSpread$
|
|
3380
|
+
var merged = _objectSpread$1(_objectSpread$1({}, DEFAULT_LIMITS), limits);
|
|
3380
3381
|
if (isImage(fileName)) return merged.image;
|
|
3381
3382
|
if (isVideo(fileName)) return merged.video;
|
|
3382
3383
|
return merged.other;
|
|
@@ -3404,7 +3405,7 @@ function _compressImageBlob() {
|
|
|
3404
3405
|
return _regeneratorRuntime.wrap(function (_context10) {
|
|
3405
3406
|
while (1) switch (_context10.prev = _context10.next) {
|
|
3406
3407
|
case 0:
|
|
3407
|
-
opts = _objectSpread$
|
|
3408
|
+
opts = _objectSpread$1(_objectSpread$1({}, DEFAULT_COMPRESS), options);
|
|
3408
3409
|
if (!(typeof createImageBitmap === "undefined" || typeof OffscreenCanvas === "undefined")) {
|
|
3409
3410
|
_context10.next = 1;
|
|
3410
3411
|
break;
|
|
@@ -3470,7 +3471,7 @@ function _processFile() {
|
|
|
3470
3471
|
return _regeneratorRuntime.wrap(function (_context11) {
|
|
3471
3472
|
while (1) switch (_context11.prev = _context11.next) {
|
|
3472
3473
|
case 0:
|
|
3473
|
-
opts = _objectSpread$
|
|
3474
|
+
opts = _objectSpread$1(_objectSpread$1({}, DEFAULT_COMPRESS), compress);
|
|
3474
3475
|
if (!(opts.enabled && isImage(fileName))) {
|
|
3475
3476
|
_context11.next = 2;
|
|
3476
3477
|
break;
|
|
@@ -3534,7 +3535,7 @@ function createOssClient() {
|
|
|
3534
3535
|
var allowedExtensions = options.allowedExtensions;
|
|
3535
3536
|
function mergeRetry(override) {
|
|
3536
3537
|
if (!defaultRetry && !override) return void 0;
|
|
3537
|
-
return _objectSpread$
|
|
3538
|
+
return _objectSpread$1(_objectSpread$1({}, defaultRetry), override);
|
|
3538
3539
|
}
|
|
3539
3540
|
function resolveCompress(override) {
|
|
3540
3541
|
if (override === false) return {
|
|
@@ -3544,7 +3545,7 @@ function createOssClient() {
|
|
|
3544
3545
|
enabled: false
|
|
3545
3546
|
};
|
|
3546
3547
|
var base = _typeof$1(defaultCompress) === "object" ? defaultCompress : {};
|
|
3547
|
-
return override ? _objectSpread$
|
|
3548
|
+
return override ? _objectSpread$1(_objectSpread$1({}, base), override) : Object.keys(base).length ? base : void 0;
|
|
3548
3549
|
}
|
|
3549
3550
|
function uploadOne(_x25, _x26, _x27, _x28) {
|
|
3550
3551
|
return _uploadOne.apply(this, arguments);
|
|
@@ -3630,7 +3631,7 @@ function createOssClient() {
|
|
|
3630
3631
|
var i = index++;
|
|
3631
3632
|
var item = files[i];
|
|
3632
3633
|
running++;
|
|
3633
|
-
var fileOpts = _objectSpread$
|
|
3634
|
+
var fileOpts = _objectSpread$1({
|
|
3634
3635
|
retry: opts === null || opts === void 0 ? void 0 : opts.retry,
|
|
3635
3636
|
compress: opts === null || opts === void 0 ? void 0 : opts.compress
|
|
3636
3637
|
}, item.options);
|
|
@@ -4046,12 +4047,12 @@ function _getSessionAdminRow() {
|
|
|
4046
4047
|
}));
|
|
4047
4048
|
return _getSessionAdminRow.apply(this, arguments);
|
|
4048
4049
|
}
|
|
4049
|
-
function
|
|
4050
|
-
return
|
|
4050
|
+
function getSessionAdminRowByEmail(_x4, _x5, _x6) {
|
|
4051
|
+
return _getSessionAdminRowByEmail.apply(this, arguments);
|
|
4051
4052
|
}
|
|
4052
|
-
function
|
|
4053
|
-
|
|
4054
|
-
var row;
|
|
4053
|
+
function _getSessionAdminRowByEmail() {
|
|
4054
|
+
_getSessionAdminRowByEmail = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, email) {
|
|
4055
|
+
var row, normalizedEmail, rowEmail;
|
|
4055
4056
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
4056
4057
|
while (1) switch (_context3.prev = _context3.next) {
|
|
4057
4058
|
case 0:
|
|
@@ -4063,15 +4064,51 @@ function _isUserSessionAdmin() {
|
|
|
4063
4064
|
_context3.next = 2;
|
|
4064
4065
|
break;
|
|
4065
4066
|
}
|
|
4066
|
-
return _context3.abrupt("return",
|
|
4067
|
+
return _context3.abrupt("return", null);
|
|
4067
4068
|
case 2:
|
|
4068
|
-
|
|
4069
|
+
normalizedEmail = (email || "").trim().toLowerCase();
|
|
4070
|
+
rowEmail = (row.email || "").trim().toLowerCase();
|
|
4071
|
+
if (!(!normalizedEmail || rowEmail !== normalizedEmail)) {
|
|
4072
|
+
_context3.next = 3;
|
|
4073
|
+
break;
|
|
4074
|
+
}
|
|
4075
|
+
return _context3.abrupt("return", null);
|
|
4069
4076
|
case 3:
|
|
4077
|
+
return _context3.abrupt("return", row);
|
|
4078
|
+
case 4:
|
|
4070
4079
|
case "end":
|
|
4071
4080
|
return _context3.stop();
|
|
4072
4081
|
}
|
|
4073
4082
|
}, _callee3);
|
|
4074
4083
|
}));
|
|
4084
|
+
return _getSessionAdminRowByEmail.apply(this, arguments);
|
|
4085
|
+
}
|
|
4086
|
+
function isUserSessionAdmin(_x7, _x8, _x9) {
|
|
4087
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
4088
|
+
}
|
|
4089
|
+
function _isUserSessionAdmin() {
|
|
4090
|
+
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(supabase, sessionId, userId) {
|
|
4091
|
+
var row;
|
|
4092
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
4093
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4094
|
+
case 0:
|
|
4095
|
+
_context4.next = 1;
|
|
4096
|
+
return getSessionAdminRow(supabase, sessionId);
|
|
4097
|
+
case 1:
|
|
4098
|
+
row = _context4.sent;
|
|
4099
|
+
if (row) {
|
|
4100
|
+
_context4.next = 2;
|
|
4101
|
+
break;
|
|
4102
|
+
}
|
|
4103
|
+
return _context4.abrupt("return", false);
|
|
4104
|
+
case 2:
|
|
4105
|
+
return _context4.abrupt("return", row.user_id === userId);
|
|
4106
|
+
case 3:
|
|
4107
|
+
case "end":
|
|
4108
|
+
return _context4.stop();
|
|
4109
|
+
}
|
|
4110
|
+
}, _callee4);
|
|
4111
|
+
}));
|
|
4075
4112
|
return _isUserSessionAdmin.apply(this, arguments);
|
|
4076
4113
|
}
|
|
4077
4114
|
|
|
@@ -4759,8 +4796,8 @@ var _excluded = ["id", "created_at", "updated_at"],
|
|
|
4759
4796
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n2 = 0, F = function F() {}; return { s: F, n: function n() { return _n2 >= r.length ? { done: !0 } : { done: !1, value: r[_n2++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
4760
4797
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4761
4798
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4762
|
-
function ownKeys
|
|
4763
|
-
function _objectSpread
|
|
4799
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4800
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4764
4801
|
function normalizeJsonLikeFields(schemaFields, payload) {
|
|
4765
4802
|
if (!schemaFields || schemaFields.length === 0) return payload;
|
|
4766
4803
|
var jsonLikeFieldNames = new Set(schemaFields.filter(function (f) {
|
|
@@ -4769,7 +4806,7 @@ function normalizeJsonLikeFields(schemaFields, payload) {
|
|
|
4769
4806
|
return f.name;
|
|
4770
4807
|
}));
|
|
4771
4808
|
if (jsonLikeFieldNames.size === 0) return payload;
|
|
4772
|
-
var normalized = _objectSpread
|
|
4809
|
+
var normalized = _objectSpread({}, payload);
|
|
4773
4810
|
for (var _i = 0, _Object$entries = Object.entries(payload); _i < _Object$entries.length; _i++) {
|
|
4774
4811
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
4775
4812
|
key = _Object$entries$_i[0],
|
|
@@ -5889,8 +5926,6 @@ var AuthUtils = /*#__PURE__*/function () {
|
|
|
5889
5926
|
}]);
|
|
5890
5927
|
}();
|
|
5891
5928
|
|
|
5892
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5893
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5894
5929
|
function getRoleFromSupabaseUser$2(user) {
|
|
5895
5930
|
var _user$app_metadata, _user$user_metadata;
|
|
5896
5931
|
var appRole = user === null || user === void 0 || (_user$app_metadata = user.app_metadata) === null || _user$app_metadata === void 0 ? void 0 : _user$app_metadata.role;
|
|
@@ -5900,10 +5935,46 @@ function getRoleFromSupabaseUser$2(user) {
|
|
|
5900
5935
|
function getAdminRegistrySetupSQL() {
|
|
5901
5936
|
return "-- Create admin registry table (run in Supabase SQL editor)\nCREATE TABLE IF NOT EXISTS \"_cms_admin_registry\" (\n session_id TEXT PRIMARY KEY,\n user_id UUID NOT NULL,\n email TEXT,\n created_at TIMESTAMPTZ DEFAULT NOW()\n);\n\nALTER TABLE \"_cms_admin_registry\" ENABLE ROW LEVEL SECURITY;\nDROP POLICY IF EXISTS \"Allow all operations\" ON \"_cms_admin_registry\";\nCREATE POLICY \"Allow all operations\" ON \"_cms_admin_registry\"\n FOR ALL USING (true) WITH CHECK (true);";
|
|
5902
5937
|
}
|
|
5903
|
-
function
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5938
|
+
function isEmailLike(value) {
|
|
5939
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim());
|
|
5940
|
+
}
|
|
5941
|
+
var PASSWORD_RESET_MESSAGES = {
|
|
5942
|
+
"zh-CN": {
|
|
5943
|
+
emailRequired: "邮箱不能为空",
|
|
5944
|
+
emailInvalid: "请输入邮箱格式的用户名",
|
|
5945
|
+
codeRequired: "验证码不能为空",
|
|
5946
|
+
passwordTooShort: "新密码至少需要 6 位",
|
|
5947
|
+
codeSent: "如果账号存在,验证码已发送",
|
|
5948
|
+
codeSendFailed: "发送重置密码验证码失败",
|
|
5949
|
+
codeSendRetry: "验证码发送失败,请稍后重试",
|
|
5950
|
+
userNotFound: "验证码无效或账号不存在",
|
|
5951
|
+
codeInvalidOrExpired: "验证码无效或已过期",
|
|
5952
|
+
resetSuccess: "密码已重置,请重新登录",
|
|
5953
|
+
resetFailed: "重置密码失败"
|
|
5954
|
+
},
|
|
5955
|
+
"en-US": {
|
|
5956
|
+
emailRequired: "Email is required",
|
|
5957
|
+
emailInvalid: "Please enter a valid email address",
|
|
5958
|
+
codeRequired: "Verification code is required",
|
|
5959
|
+
passwordTooShort: "New password must be at least 6 characters",
|
|
5960
|
+
codeSent: "If the account exists, a verification code has been sent",
|
|
5961
|
+
codeSendFailed: "Failed to send password reset code",
|
|
5962
|
+
codeSendRetry: "Failed to send verification code. Please try again later",
|
|
5963
|
+
userNotFound: "Invalid code or account not found",
|
|
5964
|
+
codeInvalidOrExpired: "Invalid or expired verification code",
|
|
5965
|
+
resetSuccess: "Password has been reset. Please log in again",
|
|
5966
|
+
resetFailed: "Failed to reset password"
|
|
5967
|
+
}
|
|
5968
|
+
};
|
|
5969
|
+
function getLocaleFromRequest(c) {
|
|
5970
|
+
var raw = (c.req.header("accept-language") || c.req.header("Accept-Language") || "").toLowerCase();
|
|
5971
|
+
if (raw.includes("en")) {
|
|
5972
|
+
return "en-US";
|
|
5973
|
+
}
|
|
5974
|
+
return "zh-CN";
|
|
5975
|
+
}
|
|
5976
|
+
function getPasswordResetMessages(c) {
|
|
5977
|
+
return PASSWORD_RESET_MESSAGES[getLocaleFromRequest(c)];
|
|
5907
5978
|
}
|
|
5908
5979
|
function toSupabaseEmail(account, sessionId) {
|
|
5909
5980
|
// 简单规则:`{session_id}_{邮箱前缀}@{邮箱后缀}`
|
|
@@ -5915,168 +5986,235 @@ function toSupabaseEmail(account, sessionId) {
|
|
|
5915
5986
|
var sid = normalizeSessionId(sessionId);
|
|
5916
5987
|
return "".concat(sid, "_").concat(localPart, "@").concat(domain);
|
|
5917
5988
|
}
|
|
5918
|
-
function
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
session_id: normalizeSessionId(sessionId),
|
|
5922
|
-
original_username: account
|
|
5923
|
-
});
|
|
5989
|
+
function isEmailVerifyError(error) {
|
|
5990
|
+
var name = String((error === null || error === void 0 ? void 0 : error.name) || "");
|
|
5991
|
+
return name === "EmailVerifyError";
|
|
5924
5992
|
}
|
|
5925
|
-
|
|
5926
|
-
|
|
5993
|
+
// POST - 发送重置密码验证码
|
|
5994
|
+
function forgotPassword(_x, _x2) {
|
|
5995
|
+
return _forgotPassword.apply(this, arguments);
|
|
5927
5996
|
}
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5997
|
+
// POST - 通过邮箱验证码重置密码
|
|
5998
|
+
function _forgotPassword() {
|
|
5999
|
+
_forgotPassword = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, tableName) {
|
|
6000
|
+
var _body$username, i18n, body, account, supabase, sessionId, adminRow, _i18n, _t3;
|
|
5931
6001
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
5932
6002
|
while (1) switch (_context2.prev = _context2.next) {
|
|
5933
6003
|
case 0:
|
|
5934
|
-
|
|
5935
|
-
|
|
6004
|
+
_context2.prev = 0;
|
|
6005
|
+
i18n = getPasswordResetMessages(c);
|
|
6006
|
+
_context2.next = 1;
|
|
6007
|
+
return c.req.json();
|
|
5936
6008
|
case 1:
|
|
5937
|
-
|
|
5938
|
-
|
|
6009
|
+
body = _context2.sent;
|
|
6010
|
+
account = (_body$username = body.username) === null || _body$username === void 0 ? void 0 : _body$username.trim();
|
|
6011
|
+
if (account) {
|
|
6012
|
+
_context2.next = 2;
|
|
5939
6013
|
break;
|
|
5940
6014
|
}
|
|
5941
|
-
_context2.
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
});
|
|
6015
|
+
return _context2.abrupt("return", c.json({
|
|
6016
|
+
success: false,
|
|
6017
|
+
message: i18n.emailRequired
|
|
6018
|
+
}, 200));
|
|
5946
6019
|
case 2:
|
|
5947
|
-
|
|
5948
|
-
data = _yield$supabase$auth$2.data;
|
|
5949
|
-
error = _yield$supabase$auth$2.error;
|
|
5950
|
-
if (!error) {
|
|
6020
|
+
if (isEmailLike(account)) {
|
|
5951
6021
|
_context2.next = 3;
|
|
5952
6022
|
break;
|
|
5953
6023
|
}
|
|
5954
|
-
|
|
6024
|
+
return _context2.abrupt("return", c.json({
|
|
6025
|
+
success: false,
|
|
6026
|
+
message: i18n.emailInvalid
|
|
6027
|
+
}, 200));
|
|
5955
6028
|
case 3:
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
});
|
|
5961
|
-
if (!matchedUser) {
|
|
5962
|
-
_context2.next = 4;
|
|
5963
|
-
break;
|
|
5964
|
-
}
|
|
5965
|
-
return _context2.abrupt("return", matchedUser);
|
|
6029
|
+
supabase = getSupabase();
|
|
6030
|
+
sessionId = extractSessionIdFromAuthTableName(tableName);
|
|
6031
|
+
_context2.next = 4;
|
|
6032
|
+
return getSessionAdminRowByEmail(supabase, sessionId, account);
|
|
5966
6033
|
case 4:
|
|
5967
|
-
|
|
6034
|
+
adminRow = _context2.sent;
|
|
6035
|
+
if (adminRow !== null && adminRow !== void 0 && adminRow.user_id) {
|
|
5968
6036
|
_context2.next = 5;
|
|
5969
6037
|
break;
|
|
5970
6038
|
}
|
|
5971
|
-
return _context2.abrupt("return",
|
|
6039
|
+
return _context2.abrupt("return", c.json({
|
|
6040
|
+
success: true,
|
|
6041
|
+
message: i18n.codeSent
|
|
6042
|
+
}, 200));
|
|
5972
6043
|
case 5:
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
break;
|
|
6044
|
+
_context2.next = 6;
|
|
6045
|
+
return emailVerify.sendCode(account);
|
|
5976
6046
|
case 6:
|
|
5977
|
-
return _context2.abrupt("return",
|
|
6047
|
+
return _context2.abrupt("return", c.json({
|
|
6048
|
+
success: true,
|
|
6049
|
+
message: i18n.codeSent
|
|
6050
|
+
}, 200));
|
|
5978
6051
|
case 7:
|
|
6052
|
+
_context2.prev = 7;
|
|
6053
|
+
_t3 = _context2["catch"](0);
|
|
6054
|
+
console.error("发送重置密码验证码失败:", _t3);
|
|
6055
|
+
_i18n = getPasswordResetMessages(c);
|
|
6056
|
+
return _context2.abrupt("return", c.json({
|
|
6057
|
+
success: false,
|
|
6058
|
+
message: isEmailVerifyError(_t3) ? _i18n.codeSendRetry : _i18n.codeSendFailed,
|
|
6059
|
+
error: _t3.message
|
|
6060
|
+
}, 500));
|
|
6061
|
+
case 8:
|
|
5979
6062
|
case "end":
|
|
5980
6063
|
return _context2.stop();
|
|
5981
6064
|
}
|
|
5982
|
-
}, _callee2);
|
|
6065
|
+
}, _callee2, null, [[0, 7]]);
|
|
5983
6066
|
}));
|
|
5984
|
-
return
|
|
6067
|
+
return _forgotPassword.apply(this, arguments);
|
|
5985
6068
|
}
|
|
5986
|
-
function
|
|
5987
|
-
return
|
|
6069
|
+
function resetPassword(_x3, _x4) {
|
|
6070
|
+
return _resetPassword.apply(this, arguments);
|
|
5988
6071
|
}
|
|
5989
|
-
function
|
|
5990
|
-
|
|
6072
|
+
function _resetPassword() {
|
|
6073
|
+
_resetPassword = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c, tableName) {
|
|
6074
|
+
var _body$username2, _body$code, i18n, body, account, code, password, supabase, sessionId, adminRow, verifyResult, _yield$supabase$auth$2, updateError, _i18n2, _t4;
|
|
5991
6075
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
5992
6076
|
while (1) switch (_context3.prev = _context3.next) {
|
|
5993
6077
|
case 0:
|
|
6078
|
+
_context3.prev = 0;
|
|
6079
|
+
i18n = getPasswordResetMessages(c);
|
|
5994
6080
|
_context3.next = 1;
|
|
5995
|
-
return
|
|
5996
|
-
session_id: normalizeSessionId(sessionId),
|
|
5997
|
-
user_id: userId,
|
|
5998
|
-
email: account
|
|
5999
|
-
});
|
|
6000
|
-
case 1:
|
|
6001
|
-
return _context3.abrupt("return", _context3.sent);
|
|
6002
|
-
case 2:
|
|
6003
|
-
case "end":
|
|
6004
|
-
return _context3.stop();
|
|
6005
|
-
}
|
|
6006
|
-
}, _callee3);
|
|
6007
|
-
}));
|
|
6008
|
-
return _insertAdminRegistryRow.apply(this, arguments);
|
|
6009
|
-
}
|
|
6010
|
-
function promoteExistingUserToSessionAdmin(_x7, _x8, _x9, _x0) {
|
|
6011
|
-
return _promoteExistingUserToSessionAdmin.apply(this, arguments);
|
|
6012
|
-
}
|
|
6013
|
-
function _promoteExistingUserToSessionAdmin() {
|
|
6014
|
-
_promoteExistingUserToSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(supabase, email, sessionId, account) {
|
|
6015
|
-
var existingUser, _yield$supabase$auth$3, updatedData, updateError, insertRes;
|
|
6016
|
-
return _regeneratorRuntime.wrap(function (_context4) {
|
|
6017
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
6018
|
-
case 0:
|
|
6019
|
-
_context4.next = 1;
|
|
6020
|
-
return findAuthUserByEmail(supabase, email);
|
|
6081
|
+
return c.req.json();
|
|
6021
6082
|
case 1:
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6083
|
+
body = _context3.sent;
|
|
6084
|
+
account = (_body$username2 = body.username) === null || _body$username2 === void 0 ? void 0 : _body$username2.trim();
|
|
6085
|
+
code = (_body$code = body.code) === null || _body$code === void 0 ? void 0 : _body$code.trim();
|
|
6086
|
+
password = body.password;
|
|
6087
|
+
if (account) {
|
|
6088
|
+
_context3.next = 2;
|
|
6025
6089
|
break;
|
|
6026
6090
|
}
|
|
6027
|
-
return
|
|
6091
|
+
return _context3.abrupt("return", c.json({
|
|
6028
6092
|
success: false,
|
|
6029
|
-
message:
|
|
6030
|
-
});
|
|
6093
|
+
message: i18n.emailRequired
|
|
6094
|
+
}, 200));
|
|
6031
6095
|
case 2:
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6096
|
+
if (isEmailLike(account)) {
|
|
6097
|
+
_context3.next = 3;
|
|
6098
|
+
break;
|
|
6099
|
+
}
|
|
6100
|
+
return _context3.abrupt("return", c.json({
|
|
6101
|
+
success: false,
|
|
6102
|
+
message: i18n.emailInvalid
|
|
6103
|
+
}, 200));
|
|
6037
6104
|
case 3:
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
updateError = _yield$supabase$auth$3.error;
|
|
6041
|
-
if (!(updateError || !(updatedData !== null && updatedData !== void 0 && updatedData.user))) {
|
|
6042
|
-
_context4.next = 4;
|
|
6105
|
+
if (code) {
|
|
6106
|
+
_context3.next = 4;
|
|
6043
6107
|
break;
|
|
6044
6108
|
}
|
|
6045
|
-
return
|
|
6109
|
+
return _context3.abrupt("return", c.json({
|
|
6046
6110
|
success: false,
|
|
6047
|
-
message:
|
|
6048
|
-
});
|
|
6111
|
+
message: i18n.codeRequired
|
|
6112
|
+
}, 200));
|
|
6049
6113
|
case 4:
|
|
6050
|
-
|
|
6051
|
-
|
|
6114
|
+
if (!(!password || password.length < 6)) {
|
|
6115
|
+
_context3.next = 5;
|
|
6116
|
+
break;
|
|
6117
|
+
}
|
|
6118
|
+
return _context3.abrupt("return", c.json({
|
|
6119
|
+
success: false,
|
|
6120
|
+
message: i18n.passwordTooShort
|
|
6121
|
+
}, 200));
|
|
6052
6122
|
case 5:
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6123
|
+
supabase = getSupabase();
|
|
6124
|
+
sessionId = extractSessionIdFromAuthTableName(tableName);
|
|
6125
|
+
_context3.next = 6;
|
|
6126
|
+
return getSessionAdminRowByEmail(supabase, sessionId, account);
|
|
6127
|
+
case 6:
|
|
6128
|
+
adminRow = _context3.sent;
|
|
6129
|
+
if (adminRow !== null && adminRow !== void 0 && adminRow.user_id) {
|
|
6130
|
+
_context3.next = 7;
|
|
6131
|
+
break;
|
|
6132
|
+
}
|
|
6133
|
+
return _context3.abrupt("return", c.json({
|
|
6134
|
+
success: false,
|
|
6135
|
+
message: i18n.userNotFound
|
|
6136
|
+
}, 200));
|
|
6137
|
+
case 7:
|
|
6138
|
+
_context3.next = 8;
|
|
6139
|
+
return emailVerify.verifyCode(account, code);
|
|
6140
|
+
case 8:
|
|
6141
|
+
verifyResult = _context3.sent;
|
|
6142
|
+
if (verifyResult !== null && verifyResult !== void 0 && verifyResult.verified) {
|
|
6143
|
+
_context3.next = 9;
|
|
6056
6144
|
break;
|
|
6057
6145
|
}
|
|
6058
|
-
return
|
|
6146
|
+
return _context3.abrupt("return", c.json({
|
|
6059
6147
|
success: false,
|
|
6060
|
-
message:
|
|
6148
|
+
message: i18n.codeInvalidOrExpired
|
|
6149
|
+
}, 200));
|
|
6150
|
+
case 9:
|
|
6151
|
+
_context3.next = 10;
|
|
6152
|
+
return supabase.auth.admin.updateUserById(adminRow.user_id, {
|
|
6153
|
+
password: password
|
|
6061
6154
|
});
|
|
6062
|
-
case
|
|
6063
|
-
|
|
6155
|
+
case 10:
|
|
6156
|
+
_yield$supabase$auth$2 = _context3.sent;
|
|
6157
|
+
updateError = _yield$supabase$auth$2.error;
|
|
6158
|
+
if (!updateError) {
|
|
6159
|
+
_context3.next = 11;
|
|
6160
|
+
break;
|
|
6161
|
+
}
|
|
6162
|
+
return _context3.abrupt("return", c.json({
|
|
6163
|
+
success: false,
|
|
6164
|
+
message: updateError.message || i18n.resetFailed
|
|
6165
|
+
}, 200));
|
|
6166
|
+
case 11:
|
|
6167
|
+
return _context3.abrupt("return", c.json({
|
|
6064
6168
|
success: true,
|
|
6065
|
-
|
|
6169
|
+
message: i18n.resetSuccess
|
|
6170
|
+
}, 200));
|
|
6171
|
+
case 12:
|
|
6172
|
+
_context3.prev = 12;
|
|
6173
|
+
_t4 = _context3["catch"](0);
|
|
6174
|
+
console.error("重置密码失败:", _t4);
|
|
6175
|
+
_i18n2 = getPasswordResetMessages(c);
|
|
6176
|
+
return _context3.abrupt("return", c.json({
|
|
6177
|
+
success: false,
|
|
6178
|
+
message: _i18n2.resetFailed,
|
|
6179
|
+
error: _t4.message
|
|
6180
|
+
}, 500));
|
|
6181
|
+
case 13:
|
|
6182
|
+
case "end":
|
|
6183
|
+
return _context3.stop();
|
|
6184
|
+
}
|
|
6185
|
+
}, _callee3, null, [[0, 12]]);
|
|
6186
|
+
}));
|
|
6187
|
+
return _resetPassword.apply(this, arguments);
|
|
6188
|
+
}
|
|
6189
|
+
function insertAdminRegistryRow(_x5, _x6, _x7, _x8) {
|
|
6190
|
+
return _insertAdminRegistryRow.apply(this, arguments);
|
|
6191
|
+
}
|
|
6192
|
+
function _insertAdminRegistryRow() {
|
|
6193
|
+
_insertAdminRegistryRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(supabase, sessionId, userId, account) {
|
|
6194
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
6195
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
6196
|
+
case 0:
|
|
6197
|
+
_context4.next = 1;
|
|
6198
|
+
return supabase.from("_cms_admin_registry").insert({
|
|
6199
|
+
session_id: normalizeSessionId(sessionId),
|
|
6200
|
+
user_id: userId,
|
|
6201
|
+
email: account
|
|
6066
6202
|
});
|
|
6067
|
-
case
|
|
6203
|
+
case 1:
|
|
6204
|
+
return _context4.abrupt("return", _context4.sent);
|
|
6205
|
+
case 2:
|
|
6068
6206
|
case "end":
|
|
6069
6207
|
return _context4.stop();
|
|
6070
6208
|
}
|
|
6071
6209
|
}, _callee4);
|
|
6072
6210
|
}));
|
|
6073
|
-
return
|
|
6211
|
+
return _insertAdminRegistryRow.apply(this, arguments);
|
|
6074
6212
|
}
|
|
6075
6213
|
function getUserSessionId(user) {
|
|
6076
6214
|
var _user$user_metadata2;
|
|
6077
6215
|
return normalizeSessionId(user === null || user === void 0 || (_user$user_metadata2 = user.user_metadata) === null || _user$user_metadata2 === void 0 ? void 0 : _user$user_metadata2.session_id);
|
|
6078
6216
|
}
|
|
6079
|
-
function getEffectiveRoleForSession(
|
|
6217
|
+
function getEffectiveRoleForSession(_x9, _x0) {
|
|
6080
6218
|
return _getEffectiveRoleForSession.apply(this, arguments);
|
|
6081
6219
|
} // POST - 用户登录
|
|
6082
6220
|
function _getEffectiveRoleForSession() {
|
|
@@ -6113,13 +6251,13 @@ function _getEffectiveRoleForSession() {
|
|
|
6113
6251
|
}));
|
|
6114
6252
|
return _getEffectiveRoleForSession.apply(this, arguments);
|
|
6115
6253
|
}
|
|
6116
|
-
function login(
|
|
6254
|
+
function login(_x1, _x10) {
|
|
6117
6255
|
return _login.apply(this, arguments);
|
|
6118
6256
|
}
|
|
6119
6257
|
// GET - 是否允许注册(首次进入需要创建管理员账号)
|
|
6120
6258
|
function _login() {
|
|
6121
6259
|
_login = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(c, tableName) {
|
|
6122
|
-
var _data$session, body, username, password, supabase, sessionId, email, _yield$supabase$auth$
|
|
6260
|
+
var _data$session, body, username, password, supabase, sessionId, email, _yield$supabase$auth$3, data, error, token, user, role, _t5;
|
|
6123
6261
|
return _regeneratorRuntime.wrap(function (_context6) {
|
|
6124
6262
|
while (1) switch (_context6.prev = _context6.next) {
|
|
6125
6263
|
case 0:
|
|
@@ -6157,9 +6295,9 @@ function _login() {
|
|
|
6157
6295
|
password: password
|
|
6158
6296
|
});
|
|
6159
6297
|
case 4:
|
|
6160
|
-
_yield$supabase$auth$
|
|
6161
|
-
data = _yield$supabase$auth$
|
|
6162
|
-
error = _yield$supabase$auth$
|
|
6298
|
+
_yield$supabase$auth$3 = _context6.sent;
|
|
6299
|
+
data = _yield$supabase$auth$3.data;
|
|
6300
|
+
error = _yield$supabase$auth$3.error;
|
|
6163
6301
|
if (!(error || !(data !== null && data !== void 0 && (_data$session = data.session) !== null && _data$session !== void 0 && _data$session.access_token) || !(data !== null && data !== void 0 && data.user))) {
|
|
6164
6302
|
_context6.next = 5;
|
|
6165
6303
|
break;
|
|
@@ -6193,12 +6331,12 @@ function _login() {
|
|
|
6193
6331
|
}, 200));
|
|
6194
6332
|
case 8:
|
|
6195
6333
|
_context6.prev = 8;
|
|
6196
|
-
|
|
6197
|
-
console.error("登录失败:",
|
|
6334
|
+
_t5 = _context6["catch"](0);
|
|
6335
|
+
console.error("登录失败:", _t5);
|
|
6198
6336
|
return _context6.abrupt("return", c.json({
|
|
6199
6337
|
success: false,
|
|
6200
6338
|
message: "登录失败",
|
|
6201
|
-
error:
|
|
6339
|
+
error: _t5.message
|
|
6202
6340
|
}, 500));
|
|
6203
6341
|
case 9:
|
|
6204
6342
|
case "end":
|
|
@@ -6208,13 +6346,13 @@ function _login() {
|
|
|
6208
6346
|
}));
|
|
6209
6347
|
return _login.apply(this, arguments);
|
|
6210
6348
|
}
|
|
6211
|
-
function signupStatus(
|
|
6349
|
+
function signupStatus(_x11, _x12) {
|
|
6212
6350
|
return _signupStatus.apply(this, arguments);
|
|
6213
6351
|
}
|
|
6214
6352
|
// POST - 首次注册管理员(每个 session_id 只允许一个)
|
|
6215
6353
|
function _signupStatus() {
|
|
6216
6354
|
_signupStatus = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(c, tableName) {
|
|
6217
|
-
var supabase, sessionId, ok, row, data,
|
|
6355
|
+
var supabase, sessionId, ok, row, data, _t6;
|
|
6218
6356
|
return _regeneratorRuntime.wrap(function (_context7) {
|
|
6219
6357
|
while (1) switch (_context7.prev = _context7.next) {
|
|
6220
6358
|
case 0:
|
|
@@ -6252,12 +6390,12 @@ function _signupStatus() {
|
|
|
6252
6390
|
}, 200));
|
|
6253
6391
|
case 4:
|
|
6254
6392
|
_context7.prev = 4;
|
|
6255
|
-
|
|
6256
|
-
console.error("获取注册状态失败:",
|
|
6393
|
+
_t6 = _context7["catch"](0);
|
|
6394
|
+
console.error("获取注册状态失败:", _t6);
|
|
6257
6395
|
return _context7.abrupt("return", c.json({
|
|
6258
6396
|
success: false,
|
|
6259
6397
|
message: "获取注册状态失败",
|
|
6260
|
-
error:
|
|
6398
|
+
error: _t6.message
|
|
6261
6399
|
}, 500));
|
|
6262
6400
|
case 5:
|
|
6263
6401
|
case "end":
|
|
@@ -6267,13 +6405,13 @@ function _signupStatus() {
|
|
|
6267
6405
|
}));
|
|
6268
6406
|
return _signupStatus.apply(this, arguments);
|
|
6269
6407
|
}
|
|
6270
|
-
function signup(
|
|
6408
|
+
function signup(_x13, _x14) {
|
|
6271
6409
|
return _signup.apply(this, arguments);
|
|
6272
6410
|
}
|
|
6273
6411
|
// POST - 验证token
|
|
6274
6412
|
function _signup() {
|
|
6275
6413
|
_signup = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(c, tableName) {
|
|
6276
|
-
var _body$
|
|
6414
|
+
var _body$username3, _data$session2, body, account, password, supabase, sessionId, email, ok, existing, _yield$supabase$auth$4, data, error, insertRes, token, user, role, _t7;
|
|
6277
6415
|
return _regeneratorRuntime.wrap(function (_context8) {
|
|
6278
6416
|
while (1) switch (_context8.prev = _context8.next) {
|
|
6279
6417
|
case 0:
|
|
@@ -6282,7 +6420,7 @@ function _signup() {
|
|
|
6282
6420
|
return c.req.json();
|
|
6283
6421
|
case 1:
|
|
6284
6422
|
body = _context8.sent;
|
|
6285
|
-
account = (_body$
|
|
6423
|
+
account = (_body$username3 = body.username) === null || _body$username3 === void 0 ? void 0 : _body$username3.trim();
|
|
6286
6424
|
password = body.password;
|
|
6287
6425
|
if (!(!account || !password)) {
|
|
6288
6426
|
_context8.next = 2;
|
|
@@ -6348,67 +6486,61 @@ function _signup() {
|
|
|
6348
6486
|
}
|
|
6349
6487
|
});
|
|
6350
6488
|
case 8:
|
|
6351
|
-
_yield$supabase$auth$
|
|
6352
|
-
data = _yield$supabase$auth$
|
|
6353
|
-
error = _yield$supabase$auth$
|
|
6489
|
+
_yield$supabase$auth$4 = _context8.sent;
|
|
6490
|
+
data = _yield$supabase$auth$4.data;
|
|
6491
|
+
error = _yield$supabase$auth$4.error;
|
|
6354
6492
|
if (!(error || !(data !== null && data !== void 0 && data.user))) {
|
|
6355
|
-
_context8.next =
|
|
6493
|
+
_context8.next = 9;
|
|
6356
6494
|
break;
|
|
6357
6495
|
}
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
if (promoted.success) {
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
}
|
|
6374
|
-
case 10:
|
|
6375
|
-
return _context8.abrupt("return", c.json({
|
|
6376
|
-
success: true,
|
|
6377
|
-
message: "管理员账号已启用,请登录"
|
|
6378
|
-
}, 200));
|
|
6379
|
-
case 11:
|
|
6496
|
+
console.log("注册失败:", error);
|
|
6497
|
+
// if (isSupabaseUserAlreadyExistsError(error)) {
|
|
6498
|
+
// const promoted = await promoteExistingUserToSessionAdmin(
|
|
6499
|
+
// supabase,
|
|
6500
|
+
// email,
|
|
6501
|
+
// sessionId,
|
|
6502
|
+
// account,
|
|
6503
|
+
// )
|
|
6504
|
+
// if (!promoted.success) {
|
|
6505
|
+
// return c.json({ success: false, message: promoted.message } as ApiResponse, 200)
|
|
6506
|
+
// }
|
|
6507
|
+
// return c.json(
|
|
6508
|
+
// { success: true, message: "管理员账号已启用,请登录" } as ApiResponse,
|
|
6509
|
+
// 200
|
|
6510
|
+
// )
|
|
6511
|
+
// }
|
|
6380
6512
|
return _context8.abrupt("return", c.json({
|
|
6381
6513
|
success: false,
|
|
6382
6514
|
message: (error === null || error === void 0 ? void 0 : error.message) || "注册失败"
|
|
6383
6515
|
}, 200));
|
|
6384
|
-
case
|
|
6516
|
+
case 9:
|
|
6385
6517
|
if ((_data$session2 = data.session) !== null && _data$session2 !== void 0 && _data$session2.access_token) {
|
|
6386
|
-
_context8.next =
|
|
6518
|
+
_context8.next = 10;
|
|
6387
6519
|
break;
|
|
6388
6520
|
}
|
|
6389
6521
|
return _context8.abrupt("return", c.json({
|
|
6390
6522
|
success: true,
|
|
6391
6523
|
message: "注册成功,请完成邮箱验证后登录"
|
|
6392
6524
|
}, 200));
|
|
6393
|
-
case
|
|
6394
|
-
_context8.next =
|
|
6525
|
+
case 10:
|
|
6526
|
+
_context8.next = 11;
|
|
6395
6527
|
return insertAdminRegistryRow(supabase, sessionId, data.user.id, account);
|
|
6396
|
-
case
|
|
6528
|
+
case 11:
|
|
6397
6529
|
insertRes = _context8.sent;
|
|
6398
6530
|
if (!insertRes.error) {
|
|
6399
|
-
_context8.next =
|
|
6531
|
+
_context8.next = 12;
|
|
6400
6532
|
break;
|
|
6401
6533
|
}
|
|
6402
6534
|
return _context8.abrupt("return", c.json({
|
|
6403
6535
|
success: false,
|
|
6404
6536
|
message: "管理员已被创建,请使用已有账号登录"
|
|
6405
6537
|
}, 200));
|
|
6406
|
-
case
|
|
6538
|
+
case 12:
|
|
6407
6539
|
token = data.session.access_token;
|
|
6408
6540
|
user = data.user;
|
|
6409
|
-
_context8.next =
|
|
6541
|
+
_context8.next = 13;
|
|
6410
6542
|
return getEffectiveRoleForSession(user, sessionId);
|
|
6411
|
-
case
|
|
6543
|
+
case 13:
|
|
6412
6544
|
role = _context8.sent;
|
|
6413
6545
|
return _context8.abrupt("return", c.json({
|
|
6414
6546
|
success: true,
|
|
@@ -6423,30 +6555,30 @@ function _signup() {
|
|
|
6423
6555
|
}
|
|
6424
6556
|
}
|
|
6425
6557
|
}, 200));
|
|
6426
|
-
case
|
|
6427
|
-
_context8.prev =
|
|
6428
|
-
|
|
6429
|
-
console.error("注册失败:",
|
|
6558
|
+
case 14:
|
|
6559
|
+
_context8.prev = 14;
|
|
6560
|
+
_t7 = _context8["catch"](0);
|
|
6561
|
+
console.error("注册失败:", _t7);
|
|
6430
6562
|
return _context8.abrupt("return", c.json({
|
|
6431
6563
|
success: false,
|
|
6432
6564
|
message: "注册失败",
|
|
6433
|
-
error:
|
|
6565
|
+
error: _t7.message
|
|
6434
6566
|
}, 500));
|
|
6435
|
-
case
|
|
6567
|
+
case 15:
|
|
6436
6568
|
case "end":
|
|
6437
6569
|
return _context8.stop();
|
|
6438
6570
|
}
|
|
6439
|
-
}, _callee8, null, [[0,
|
|
6571
|
+
}, _callee8, null, [[0, 14]]);
|
|
6440
6572
|
}));
|
|
6441
6573
|
return _signup.apply(this, arguments);
|
|
6442
6574
|
}
|
|
6443
|
-
function verifyAuth(
|
|
6575
|
+
function verifyAuth(_x15, _x16) {
|
|
6444
6576
|
return _verifyAuth.apply(this, arguments);
|
|
6445
6577
|
}
|
|
6446
6578
|
// GET - 获取当前用户信息
|
|
6447
6579
|
function _verifyAuth() {
|
|
6448
6580
|
_verifyAuth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(c, tableName) {
|
|
6449
|
-
var authHeader, token, supabase, _yield$supabase$auth$
|
|
6581
|
+
var authHeader, token, supabase, _yield$supabase$auth$5, data, error, sessionId, role, decoded, message, responseMessage, _t8, _t9;
|
|
6450
6582
|
return _regeneratorRuntime.wrap(function (_context9) {
|
|
6451
6583
|
while (1) switch (_context9.prev = _context9.next) {
|
|
6452
6584
|
case 0:
|
|
@@ -6467,9 +6599,9 @@ function _verifyAuth() {
|
|
|
6467
6599
|
_context9.next = 2;
|
|
6468
6600
|
return supabase.auth.getUser(token);
|
|
6469
6601
|
case 2:
|
|
6470
|
-
_yield$supabase$auth$
|
|
6471
|
-
data = _yield$supabase$auth$
|
|
6472
|
-
error = _yield$supabase$auth$
|
|
6602
|
+
_yield$supabase$auth$5 = _context9.sent;
|
|
6603
|
+
data = _yield$supabase$auth$5.data;
|
|
6604
|
+
error = _yield$supabase$auth$5.error;
|
|
6473
6605
|
if (!(error || !(data !== null && data !== void 0 && data.user))) {
|
|
6474
6606
|
_context9.next = 3;
|
|
6475
6607
|
break;
|
|
@@ -6496,8 +6628,8 @@ function _verifyAuth() {
|
|
|
6496
6628
|
}));
|
|
6497
6629
|
case 6:
|
|
6498
6630
|
_context9.prev = 6;
|
|
6499
|
-
|
|
6500
|
-
message =
|
|
6631
|
+
_t8 = _context9["catch"](1);
|
|
6632
|
+
message = _t8.message;
|
|
6501
6633
|
responseMessage = message === 'TOKEN_EXPIRED' ? "登录已过期,请重新登录" : "认证信息无效";
|
|
6502
6634
|
return _context9.abrupt("return", c.json({
|
|
6503
6635
|
success: false,
|
|
@@ -6505,12 +6637,12 @@ function _verifyAuth() {
|
|
|
6505
6637
|
}, 200));
|
|
6506
6638
|
case 7:
|
|
6507
6639
|
_context9.prev = 7;
|
|
6508
|
-
|
|
6509
|
-
console.error("验证认证失败:",
|
|
6640
|
+
_t9 = _context9["catch"](0);
|
|
6641
|
+
console.error("验证认证失败:", _t9);
|
|
6510
6642
|
return _context9.abrupt("return", c.json({
|
|
6511
6643
|
success: false,
|
|
6512
6644
|
message: "验证认证失败",
|
|
6513
|
-
error:
|
|
6645
|
+
error: _t9.message
|
|
6514
6646
|
}, 500));
|
|
6515
6647
|
case 8:
|
|
6516
6648
|
case "end":
|
|
@@ -6520,13 +6652,13 @@ function _verifyAuth() {
|
|
|
6520
6652
|
}));
|
|
6521
6653
|
return _verifyAuth.apply(this, arguments);
|
|
6522
6654
|
}
|
|
6523
|
-
function getCurrentUser(
|
|
6655
|
+
function getCurrentUser(_x17, _x18) {
|
|
6524
6656
|
return _getCurrentUser.apply(this, arguments);
|
|
6525
6657
|
}
|
|
6526
6658
|
// 中间件:验证 Supabase JWT token
|
|
6527
6659
|
function _getCurrentUser() {
|
|
6528
6660
|
_getCurrentUser = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(c, tableName) {
|
|
6529
|
-
var authHeader, token, supabase, _yield$supabase$auth$
|
|
6661
|
+
var authHeader, token, supabase, _yield$supabase$auth$6, data, error, user, sessionId, role, _t0;
|
|
6530
6662
|
return _regeneratorRuntime.wrap(function (_context0) {
|
|
6531
6663
|
while (1) switch (_context0.prev = _context0.next) {
|
|
6532
6664
|
case 0:
|
|
@@ -6546,9 +6678,9 @@ function _getCurrentUser() {
|
|
|
6546
6678
|
_context0.next = 2;
|
|
6547
6679
|
return supabase.auth.getUser(token);
|
|
6548
6680
|
case 2:
|
|
6549
|
-
_yield$supabase$auth$
|
|
6550
|
-
data = _yield$supabase$auth$
|
|
6551
|
-
error = _yield$supabase$auth$
|
|
6681
|
+
_yield$supabase$auth$6 = _context0.sent;
|
|
6682
|
+
data = _yield$supabase$auth$6.data;
|
|
6683
|
+
error = _yield$supabase$auth$6.error;
|
|
6552
6684
|
if (!(error || !(data !== null && data !== void 0 && data.user))) {
|
|
6553
6685
|
_context0.next = 3;
|
|
6554
6686
|
break;
|
|
@@ -6581,12 +6713,12 @@ function _getCurrentUser() {
|
|
|
6581
6713
|
}, 200));
|
|
6582
6714
|
case 6:
|
|
6583
6715
|
_context0.prev = 6;
|
|
6584
|
-
|
|
6585
|
-
console.error("获取用户信息失败:",
|
|
6716
|
+
_t0 = _context0["catch"](0);
|
|
6717
|
+
console.error("获取用户信息失败:", _t0);
|
|
6586
6718
|
return _context0.abrupt("return", c.json({
|
|
6587
6719
|
success: false,
|
|
6588
6720
|
message: "获取用户信息失败",
|
|
6589
|
-
error:
|
|
6721
|
+
error: _t0.message
|
|
6590
6722
|
}, 500));
|
|
6591
6723
|
case 7:
|
|
6592
6724
|
case "end":
|
|
@@ -6666,7 +6798,7 @@ function requireAuth(handler) {
|
|
|
6666
6798
|
}
|
|
6667
6799
|
}, _callee, null, [[0, 5], [1, 4]]);
|
|
6668
6800
|
}));
|
|
6669
|
-
return function (
|
|
6801
|
+
return function (_x19) {
|
|
6670
6802
|
return _ref.apply(this, arguments);
|
|
6671
6803
|
};
|
|
6672
6804
|
}();
|
|
@@ -7237,10 +7369,26 @@ function createDynamicAuthRoute(app) {
|
|
|
7237
7369
|
var tableName = c.req.param("tableName");
|
|
7238
7370
|
return signup(c, tableName);
|
|
7239
7371
|
});
|
|
7372
|
+
app.post("/auth/password/forgot/:tableName", function (c) {
|
|
7373
|
+
var tableName = c.req.param("tableName");
|
|
7374
|
+
return forgotPassword(c, tableName);
|
|
7375
|
+
});
|
|
7376
|
+
app.post("/auth/password/reset/:tableName", function (c) {
|
|
7377
|
+
var tableName = c.req.param("tableName");
|
|
7378
|
+
return resetPassword(c, tableName);
|
|
7379
|
+
});
|
|
7240
7380
|
app.post("/auth/:tableName/login", function (c) {
|
|
7241
7381
|
var tableName = c.req.param("tableName");
|
|
7242
7382
|
return login(c, tableName);
|
|
7243
7383
|
});
|
|
7384
|
+
app.post("/auth/:tableName/password/forgot", function (c) {
|
|
7385
|
+
var tableName = c.req.param("tableName");
|
|
7386
|
+
return forgotPassword(c, tableName);
|
|
7387
|
+
});
|
|
7388
|
+
app.post("/auth/:tableName/password/reset", function (c) {
|
|
7389
|
+
var tableName = c.req.param("tableName");
|
|
7390
|
+
return resetPassword(c, tableName);
|
|
7391
|
+
});
|
|
7244
7392
|
app.get("/auth/:tableName/current", function (c) {
|
|
7245
7393
|
var tableName = c.req.param("tableName");
|
|
7246
7394
|
return getCurrentUser(c, tableName);
|