@wecode-team/cms-supabase-api 0.1.48 → 0.1.50
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.d.ts +2 -2
- package/dist/index.esm.js +362 -214
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +363 -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.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createClient } from '@supabase/supabase-js';
|
|
2
|
+
import { sendCode, verifyCode } from '@wecode-team/email-verify';
|
|
2
3
|
import * as jwt from 'jsonwebtoken';
|
|
3
4
|
import * as bcrypt from 'bcryptjs';
|
|
4
5
|
|
|
@@ -1011,8 +1012,8 @@ function _defineProperty(e, r, t) {
|
|
|
1011
1012
|
}) : e[r] = t, e;
|
|
1012
1013
|
}
|
|
1013
1014
|
|
|
1014
|
-
function ownKeys$
|
|
1015
|
-
function _objectSpread$
|
|
1015
|
+
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; }
|
|
1016
|
+
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; }
|
|
1016
1017
|
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; } } }; }
|
|
1017
1018
|
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; } }
|
|
1018
1019
|
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; }
|
|
@@ -2068,7 +2069,7 @@ var DynamicTableService = /*#__PURE__*/function () {
|
|
|
2068
2069
|
throw error;
|
|
2069
2070
|
case 2:
|
|
2070
2071
|
return _context14.abrupt("return", (data || []).map(function (item) {
|
|
2071
|
-
return _objectSpread$
|
|
2072
|
+
return _objectSpread$3({
|
|
2072
2073
|
id: item.id,
|
|
2073
2074
|
label: item[displayField] || "ID: ".concat(item.id)
|
|
2074
2075
|
}, item);
|
|
@@ -2181,8 +2182,8 @@ function getDynamicTableService() {
|
|
|
2181
2182
|
return defaultService$1;
|
|
2182
2183
|
}
|
|
2183
2184
|
|
|
2184
|
-
function ownKeys$
|
|
2185
|
-
function _objectSpread$
|
|
2185
|
+
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; }
|
|
2186
|
+
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; }
|
|
2186
2187
|
var AuthService = /*#__PURE__*/function () {
|
|
2187
2188
|
function AuthService() {
|
|
2188
2189
|
_classCallCheck(this, AuthService);
|
|
@@ -2359,7 +2360,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2359
2360
|
return _regeneratorRuntime.wrap(function (_context4) {
|
|
2360
2361
|
while (1) switch (_context4.prev = _context4.next) {
|
|
2361
2362
|
case 0:
|
|
2362
|
-
finalUserData = _objectSpread$
|
|
2363
|
+
finalUserData = _objectSpread$2({
|
|
2363
2364
|
tableName: this.defaultTableName
|
|
2364
2365
|
}, userData);
|
|
2365
2366
|
_context4.prev = 1;
|
|
@@ -2417,7 +2418,7 @@ var AuthService = /*#__PURE__*/function () {
|
|
|
2417
2418
|
case 0:
|
|
2418
2419
|
updateData = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
|
|
2419
2420
|
// 设置默认值
|
|
2420
|
-
finalUpdateData = _objectSpread$
|
|
2421
|
+
finalUpdateData = _objectSpread$2({
|
|
2421
2422
|
tableName: this.defaultTableName
|
|
2422
2423
|
}, updateData);
|
|
2423
2424
|
_context5.prev = 1;
|
|
@@ -2825,8 +2826,8 @@ function _toConsumableArray(r) {
|
|
|
2825
2826
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray$2(r) || _nonIterableSpread();
|
|
2826
2827
|
}
|
|
2827
2828
|
|
|
2828
|
-
function ownKeys$
|
|
2829
|
-
function _objectSpread$
|
|
2829
|
+
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; }
|
|
2830
|
+
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; }
|
|
2830
2831
|
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)); }
|
|
2831
2832
|
function _isNativeReflectConstruct$1() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct$1 = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
2832
2833
|
// src/error.ts
|
|
@@ -3354,7 +3355,7 @@ var DEFAULT_LIMITS = {
|
|
|
3354
3355
|
other: 10 * 1024 * 1024
|
|
3355
3356
|
};
|
|
3356
3357
|
function getSizeLimit(fileName, limits) {
|
|
3357
|
-
var merged = _objectSpread$
|
|
3358
|
+
var merged = _objectSpread$1(_objectSpread$1({}, DEFAULT_LIMITS), limits);
|
|
3358
3359
|
if (isImage(fileName)) return merged.image;
|
|
3359
3360
|
if (isVideo(fileName)) return merged.video;
|
|
3360
3361
|
return merged.other;
|
|
@@ -3382,7 +3383,7 @@ function _compressImageBlob() {
|
|
|
3382
3383
|
return _regeneratorRuntime.wrap(function (_context10) {
|
|
3383
3384
|
while (1) switch (_context10.prev = _context10.next) {
|
|
3384
3385
|
case 0:
|
|
3385
|
-
opts = _objectSpread$
|
|
3386
|
+
opts = _objectSpread$1(_objectSpread$1({}, DEFAULT_COMPRESS), options);
|
|
3386
3387
|
if (!(typeof createImageBitmap === "undefined" || typeof OffscreenCanvas === "undefined")) {
|
|
3387
3388
|
_context10.next = 1;
|
|
3388
3389
|
break;
|
|
@@ -3448,7 +3449,7 @@ function _processFile() {
|
|
|
3448
3449
|
return _regeneratorRuntime.wrap(function (_context11) {
|
|
3449
3450
|
while (1) switch (_context11.prev = _context11.next) {
|
|
3450
3451
|
case 0:
|
|
3451
|
-
opts = _objectSpread$
|
|
3452
|
+
opts = _objectSpread$1(_objectSpread$1({}, DEFAULT_COMPRESS), compress);
|
|
3452
3453
|
if (!(opts.enabled && isImage(fileName))) {
|
|
3453
3454
|
_context11.next = 2;
|
|
3454
3455
|
break;
|
|
@@ -3512,7 +3513,7 @@ function createOssClient() {
|
|
|
3512
3513
|
var allowedExtensions = options.allowedExtensions;
|
|
3513
3514
|
function mergeRetry(override) {
|
|
3514
3515
|
if (!defaultRetry && !override) return void 0;
|
|
3515
|
-
return _objectSpread$
|
|
3516
|
+
return _objectSpread$1(_objectSpread$1({}, defaultRetry), override);
|
|
3516
3517
|
}
|
|
3517
3518
|
function resolveCompress(override) {
|
|
3518
3519
|
if (override === false) return {
|
|
@@ -3522,7 +3523,7 @@ function createOssClient() {
|
|
|
3522
3523
|
enabled: false
|
|
3523
3524
|
};
|
|
3524
3525
|
var base = _typeof$1(defaultCompress) === "object" ? defaultCompress : {};
|
|
3525
|
-
return override ? _objectSpread$
|
|
3526
|
+
return override ? _objectSpread$1(_objectSpread$1({}, base), override) : Object.keys(base).length ? base : void 0;
|
|
3526
3527
|
}
|
|
3527
3528
|
function uploadOne(_x25, _x26, _x27, _x28) {
|
|
3528
3529
|
return _uploadOne.apply(this, arguments);
|
|
@@ -3608,7 +3609,7 @@ function createOssClient() {
|
|
|
3608
3609
|
var i = index++;
|
|
3609
3610
|
var item = files[i];
|
|
3610
3611
|
running++;
|
|
3611
|
-
var fileOpts = _objectSpread$
|
|
3612
|
+
var fileOpts = _objectSpread$1({
|
|
3612
3613
|
retry: opts === null || opts === void 0 ? void 0 : opts.retry,
|
|
3613
3614
|
compress: opts === null || opts === void 0 ? void 0 : opts.compress
|
|
3614
3615
|
}, item.options);
|
|
@@ -4024,12 +4025,12 @@ function _getSessionAdminRow() {
|
|
|
4024
4025
|
}));
|
|
4025
4026
|
return _getSessionAdminRow.apply(this, arguments);
|
|
4026
4027
|
}
|
|
4027
|
-
function
|
|
4028
|
-
return
|
|
4028
|
+
function getSessionAdminRowByEmail(_x4, _x5, _x6) {
|
|
4029
|
+
return _getSessionAdminRowByEmail.apply(this, arguments);
|
|
4029
4030
|
}
|
|
4030
|
-
function
|
|
4031
|
-
|
|
4032
|
-
var row;
|
|
4031
|
+
function _getSessionAdminRowByEmail() {
|
|
4032
|
+
_getSessionAdminRowByEmail = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(supabase, sessionId, email) {
|
|
4033
|
+
var row, normalizedEmail, rowEmail;
|
|
4033
4034
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
4034
4035
|
while (1) switch (_context3.prev = _context3.next) {
|
|
4035
4036
|
case 0:
|
|
@@ -4041,15 +4042,51 @@ function _isUserSessionAdmin() {
|
|
|
4041
4042
|
_context3.next = 2;
|
|
4042
4043
|
break;
|
|
4043
4044
|
}
|
|
4044
|
-
return _context3.abrupt("return",
|
|
4045
|
+
return _context3.abrupt("return", null);
|
|
4045
4046
|
case 2:
|
|
4046
|
-
|
|
4047
|
+
normalizedEmail = (email || "").trim().toLowerCase();
|
|
4048
|
+
rowEmail = (row.email || "").trim().toLowerCase();
|
|
4049
|
+
if (!(!normalizedEmail || rowEmail !== normalizedEmail)) {
|
|
4050
|
+
_context3.next = 3;
|
|
4051
|
+
break;
|
|
4052
|
+
}
|
|
4053
|
+
return _context3.abrupt("return", null);
|
|
4047
4054
|
case 3:
|
|
4055
|
+
return _context3.abrupt("return", row);
|
|
4056
|
+
case 4:
|
|
4048
4057
|
case "end":
|
|
4049
4058
|
return _context3.stop();
|
|
4050
4059
|
}
|
|
4051
4060
|
}, _callee3);
|
|
4052
4061
|
}));
|
|
4062
|
+
return _getSessionAdminRowByEmail.apply(this, arguments);
|
|
4063
|
+
}
|
|
4064
|
+
function isUserSessionAdmin(_x7, _x8, _x9) {
|
|
4065
|
+
return _isUserSessionAdmin.apply(this, arguments);
|
|
4066
|
+
}
|
|
4067
|
+
function _isUserSessionAdmin() {
|
|
4068
|
+
_isUserSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(supabase, sessionId, userId) {
|
|
4069
|
+
var row;
|
|
4070
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
4071
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
4072
|
+
case 0:
|
|
4073
|
+
_context4.next = 1;
|
|
4074
|
+
return getSessionAdminRow(supabase, sessionId);
|
|
4075
|
+
case 1:
|
|
4076
|
+
row = _context4.sent;
|
|
4077
|
+
if (row) {
|
|
4078
|
+
_context4.next = 2;
|
|
4079
|
+
break;
|
|
4080
|
+
}
|
|
4081
|
+
return _context4.abrupt("return", false);
|
|
4082
|
+
case 2:
|
|
4083
|
+
return _context4.abrupt("return", row.user_id === userId);
|
|
4084
|
+
case 3:
|
|
4085
|
+
case "end":
|
|
4086
|
+
return _context4.stop();
|
|
4087
|
+
}
|
|
4088
|
+
}, _callee4);
|
|
4089
|
+
}));
|
|
4053
4090
|
return _isUserSessionAdmin.apply(this, arguments);
|
|
4054
4091
|
}
|
|
4055
4092
|
|
|
@@ -4737,8 +4774,8 @@ var _excluded = ["id", "created_at", "updated_at"],
|
|
|
4737
4774
|
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; } } }; }
|
|
4738
4775
|
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; } }
|
|
4739
4776
|
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; }
|
|
4740
|
-
function ownKeys
|
|
4741
|
-
function _objectSpread
|
|
4777
|
+
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; }
|
|
4778
|
+
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; }
|
|
4742
4779
|
function normalizeJsonLikeFields(schemaFields, payload) {
|
|
4743
4780
|
if (!schemaFields || schemaFields.length === 0) return payload;
|
|
4744
4781
|
var jsonLikeFieldNames = new Set(schemaFields.filter(function (f) {
|
|
@@ -4747,7 +4784,7 @@ function normalizeJsonLikeFields(schemaFields, payload) {
|
|
|
4747
4784
|
return f.name;
|
|
4748
4785
|
}));
|
|
4749
4786
|
if (jsonLikeFieldNames.size === 0) return payload;
|
|
4750
|
-
var normalized = _objectSpread
|
|
4787
|
+
var normalized = _objectSpread({}, payload);
|
|
4751
4788
|
for (var _i = 0, _Object$entries = Object.entries(payload); _i < _Object$entries.length; _i++) {
|
|
4752
4789
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
4753
4790
|
key = _Object$entries$_i[0],
|
|
@@ -5867,8 +5904,6 @@ var AuthUtils = /*#__PURE__*/function () {
|
|
|
5867
5904
|
}]);
|
|
5868
5905
|
}();
|
|
5869
5906
|
|
|
5870
|
-
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; }
|
|
5871
|
-
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; }
|
|
5872
5907
|
function getRoleFromSupabaseUser$2(user) {
|
|
5873
5908
|
var _user$app_metadata, _user$user_metadata;
|
|
5874
5909
|
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;
|
|
@@ -5878,10 +5913,46 @@ function getRoleFromSupabaseUser$2(user) {
|
|
|
5878
5913
|
function getAdminRegistrySetupSQL() {
|
|
5879
5914
|
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);";
|
|
5880
5915
|
}
|
|
5881
|
-
function
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5916
|
+
function isEmailLike(value) {
|
|
5917
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim());
|
|
5918
|
+
}
|
|
5919
|
+
var PASSWORD_RESET_MESSAGES = {
|
|
5920
|
+
"zh-CN": {
|
|
5921
|
+
emailRequired: "邮箱不能为空",
|
|
5922
|
+
emailInvalid: "请输入邮箱格式的用户名",
|
|
5923
|
+
codeRequired: "验证码不能为空",
|
|
5924
|
+
passwordTooShort: "新密码至少需要 6 位",
|
|
5925
|
+
codeSent: "如果账号存在,验证码已发送",
|
|
5926
|
+
codeSendFailed: "发送重置密码验证码失败",
|
|
5927
|
+
codeSendRetry: "验证码发送失败,请稍后重试",
|
|
5928
|
+
userNotFound: "验证码无效或账号不存在",
|
|
5929
|
+
codeInvalidOrExpired: "验证码无效或已过期",
|
|
5930
|
+
resetSuccess: "密码已重置,请重新登录",
|
|
5931
|
+
resetFailed: "重置密码失败"
|
|
5932
|
+
},
|
|
5933
|
+
"en-US": {
|
|
5934
|
+
emailRequired: "Email is required",
|
|
5935
|
+
emailInvalid: "Please enter a valid email address",
|
|
5936
|
+
codeRequired: "Verification code is required",
|
|
5937
|
+
passwordTooShort: "New password must be at least 6 characters",
|
|
5938
|
+
codeSent: "If the account exists, a verification code has been sent",
|
|
5939
|
+
codeSendFailed: "Failed to send password reset code",
|
|
5940
|
+
codeSendRetry: "Failed to send verification code. Please try again later",
|
|
5941
|
+
userNotFound: "Invalid code or account not found",
|
|
5942
|
+
codeInvalidOrExpired: "Invalid or expired verification code",
|
|
5943
|
+
resetSuccess: "Password has been reset. Please log in again",
|
|
5944
|
+
resetFailed: "Failed to reset password"
|
|
5945
|
+
}
|
|
5946
|
+
};
|
|
5947
|
+
function getLocaleFromRequest(c) {
|
|
5948
|
+
var raw = (c.req.header("accept-language") || c.req.header("Accept-Language") || "").toLowerCase();
|
|
5949
|
+
if (raw.includes("en")) {
|
|
5950
|
+
return "en-US";
|
|
5951
|
+
}
|
|
5952
|
+
return "zh-CN";
|
|
5953
|
+
}
|
|
5954
|
+
function getPasswordResetMessages(c) {
|
|
5955
|
+
return PASSWORD_RESET_MESSAGES[getLocaleFromRequest(c)];
|
|
5885
5956
|
}
|
|
5886
5957
|
function toSupabaseEmail(account, sessionId) {
|
|
5887
5958
|
// 简单规则:`{session_id}_{邮箱前缀}@{邮箱后缀}`
|
|
@@ -5893,168 +5964,235 @@ function toSupabaseEmail(account, sessionId) {
|
|
|
5893
5964
|
var sid = normalizeSessionId(sessionId);
|
|
5894
5965
|
return "".concat(sid, "_").concat(localPart, "@").concat(domain);
|
|
5895
5966
|
}
|
|
5896
|
-
function
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
session_id: normalizeSessionId(sessionId),
|
|
5900
|
-
original_username: account
|
|
5901
|
-
});
|
|
5967
|
+
function isEmailVerifyError(error) {
|
|
5968
|
+
var name = String((error === null || error === void 0 ? void 0 : error.name) || "");
|
|
5969
|
+
return name === "EmailVerifyError";
|
|
5902
5970
|
}
|
|
5903
|
-
|
|
5904
|
-
|
|
5971
|
+
// POST - 发送重置密码验证码
|
|
5972
|
+
function forgotPassword(_x, _x2) {
|
|
5973
|
+
return _forgotPassword.apply(this, arguments);
|
|
5905
5974
|
}
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5975
|
+
// POST - 通过邮箱验证码重置密码
|
|
5976
|
+
function _forgotPassword() {
|
|
5977
|
+
_forgotPassword = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(c, tableName) {
|
|
5978
|
+
var _body$username, i18n, body, account, supabase, sessionId, adminRow, _i18n, _t3;
|
|
5909
5979
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
5910
5980
|
while (1) switch (_context2.prev = _context2.next) {
|
|
5911
5981
|
case 0:
|
|
5912
|
-
|
|
5913
|
-
|
|
5982
|
+
_context2.prev = 0;
|
|
5983
|
+
i18n = getPasswordResetMessages(c);
|
|
5984
|
+
_context2.next = 1;
|
|
5985
|
+
return c.req.json();
|
|
5914
5986
|
case 1:
|
|
5915
|
-
|
|
5916
|
-
|
|
5987
|
+
body = _context2.sent;
|
|
5988
|
+
account = (_body$username = body.username) === null || _body$username === void 0 ? void 0 : _body$username.trim();
|
|
5989
|
+
if (account) {
|
|
5990
|
+
_context2.next = 2;
|
|
5917
5991
|
break;
|
|
5918
5992
|
}
|
|
5919
|
-
_context2.
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
});
|
|
5993
|
+
return _context2.abrupt("return", c.json({
|
|
5994
|
+
success: false,
|
|
5995
|
+
message: i18n.emailRequired
|
|
5996
|
+
}, 200));
|
|
5924
5997
|
case 2:
|
|
5925
|
-
|
|
5926
|
-
data = _yield$supabase$auth$2.data;
|
|
5927
|
-
error = _yield$supabase$auth$2.error;
|
|
5928
|
-
if (!error) {
|
|
5998
|
+
if (isEmailLike(account)) {
|
|
5929
5999
|
_context2.next = 3;
|
|
5930
6000
|
break;
|
|
5931
6001
|
}
|
|
5932
|
-
|
|
6002
|
+
return _context2.abrupt("return", c.json({
|
|
6003
|
+
success: false,
|
|
6004
|
+
message: i18n.emailInvalid
|
|
6005
|
+
}, 200));
|
|
5933
6006
|
case 3:
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
});
|
|
5939
|
-
if (!matchedUser) {
|
|
5940
|
-
_context2.next = 4;
|
|
5941
|
-
break;
|
|
5942
|
-
}
|
|
5943
|
-
return _context2.abrupt("return", matchedUser);
|
|
6007
|
+
supabase = getSupabase();
|
|
6008
|
+
sessionId = extractSessionIdFromAuthTableName(tableName);
|
|
6009
|
+
_context2.next = 4;
|
|
6010
|
+
return getSessionAdminRowByEmail(supabase, sessionId, account);
|
|
5944
6011
|
case 4:
|
|
5945
|
-
|
|
6012
|
+
adminRow = _context2.sent;
|
|
6013
|
+
if (adminRow !== null && adminRow !== void 0 && adminRow.user_id) {
|
|
5946
6014
|
_context2.next = 5;
|
|
5947
6015
|
break;
|
|
5948
6016
|
}
|
|
5949
|
-
return _context2.abrupt("return",
|
|
6017
|
+
return _context2.abrupt("return", c.json({
|
|
6018
|
+
success: true,
|
|
6019
|
+
message: i18n.codeSent
|
|
6020
|
+
}, 200));
|
|
5950
6021
|
case 5:
|
|
5951
|
-
|
|
5952
|
-
|
|
5953
|
-
break;
|
|
6022
|
+
_context2.next = 6;
|
|
6023
|
+
return sendCode(account);
|
|
5954
6024
|
case 6:
|
|
5955
|
-
return _context2.abrupt("return",
|
|
6025
|
+
return _context2.abrupt("return", c.json({
|
|
6026
|
+
success: true,
|
|
6027
|
+
message: i18n.codeSent
|
|
6028
|
+
}, 200));
|
|
5956
6029
|
case 7:
|
|
6030
|
+
_context2.prev = 7;
|
|
6031
|
+
_t3 = _context2["catch"](0);
|
|
6032
|
+
console.error("发送重置密码验证码失败:", _t3);
|
|
6033
|
+
_i18n = getPasswordResetMessages(c);
|
|
6034
|
+
return _context2.abrupt("return", c.json({
|
|
6035
|
+
success: false,
|
|
6036
|
+
message: isEmailVerifyError(_t3) ? _i18n.codeSendRetry : _i18n.codeSendFailed,
|
|
6037
|
+
error: _t3.message
|
|
6038
|
+
}, 500));
|
|
6039
|
+
case 8:
|
|
5957
6040
|
case "end":
|
|
5958
6041
|
return _context2.stop();
|
|
5959
6042
|
}
|
|
5960
|
-
}, _callee2);
|
|
6043
|
+
}, _callee2, null, [[0, 7]]);
|
|
5961
6044
|
}));
|
|
5962
|
-
return
|
|
6045
|
+
return _forgotPassword.apply(this, arguments);
|
|
5963
6046
|
}
|
|
5964
|
-
function
|
|
5965
|
-
return
|
|
6047
|
+
function resetPassword(_x3, _x4) {
|
|
6048
|
+
return _resetPassword.apply(this, arguments);
|
|
5966
6049
|
}
|
|
5967
|
-
function
|
|
5968
|
-
|
|
6050
|
+
function _resetPassword() {
|
|
6051
|
+
_resetPassword = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(c, tableName) {
|
|
6052
|
+
var _body$username2, _body$code, i18n, body, account, code, password, supabase, sessionId, adminRow, verifyResult, _yield$supabase$auth$2, updateError, _i18n2, _t4;
|
|
5969
6053
|
return _regeneratorRuntime.wrap(function (_context3) {
|
|
5970
6054
|
while (1) switch (_context3.prev = _context3.next) {
|
|
5971
6055
|
case 0:
|
|
6056
|
+
_context3.prev = 0;
|
|
6057
|
+
i18n = getPasswordResetMessages(c);
|
|
5972
6058
|
_context3.next = 1;
|
|
5973
|
-
return
|
|
5974
|
-
session_id: normalizeSessionId(sessionId),
|
|
5975
|
-
user_id: userId,
|
|
5976
|
-
email: account
|
|
5977
|
-
});
|
|
5978
|
-
case 1:
|
|
5979
|
-
return _context3.abrupt("return", _context3.sent);
|
|
5980
|
-
case 2:
|
|
5981
|
-
case "end":
|
|
5982
|
-
return _context3.stop();
|
|
5983
|
-
}
|
|
5984
|
-
}, _callee3);
|
|
5985
|
-
}));
|
|
5986
|
-
return _insertAdminRegistryRow.apply(this, arguments);
|
|
5987
|
-
}
|
|
5988
|
-
function promoteExistingUserToSessionAdmin(_x7, _x8, _x9, _x0) {
|
|
5989
|
-
return _promoteExistingUserToSessionAdmin.apply(this, arguments);
|
|
5990
|
-
}
|
|
5991
|
-
function _promoteExistingUserToSessionAdmin() {
|
|
5992
|
-
_promoteExistingUserToSessionAdmin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(supabase, email, sessionId, account) {
|
|
5993
|
-
var existingUser, _yield$supabase$auth$3, updatedData, updateError, insertRes;
|
|
5994
|
-
return _regeneratorRuntime.wrap(function (_context4) {
|
|
5995
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
5996
|
-
case 0:
|
|
5997
|
-
_context4.next = 1;
|
|
5998
|
-
return findAuthUserByEmail(supabase, email);
|
|
6059
|
+
return c.req.json();
|
|
5999
6060
|
case 1:
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6061
|
+
body = _context3.sent;
|
|
6062
|
+
account = (_body$username2 = body.username) === null || _body$username2 === void 0 ? void 0 : _body$username2.trim();
|
|
6063
|
+
code = (_body$code = body.code) === null || _body$code === void 0 ? void 0 : _body$code.trim();
|
|
6064
|
+
password = body.password;
|
|
6065
|
+
if (account) {
|
|
6066
|
+
_context3.next = 2;
|
|
6003
6067
|
break;
|
|
6004
6068
|
}
|
|
6005
|
-
return
|
|
6069
|
+
return _context3.abrupt("return", c.json({
|
|
6006
6070
|
success: false,
|
|
6007
|
-
message:
|
|
6008
|
-
});
|
|
6071
|
+
message: i18n.emailRequired
|
|
6072
|
+
}, 200));
|
|
6009
6073
|
case 2:
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6074
|
+
if (isEmailLike(account)) {
|
|
6075
|
+
_context3.next = 3;
|
|
6076
|
+
break;
|
|
6077
|
+
}
|
|
6078
|
+
return _context3.abrupt("return", c.json({
|
|
6079
|
+
success: false,
|
|
6080
|
+
message: i18n.emailInvalid
|
|
6081
|
+
}, 200));
|
|
6015
6082
|
case 3:
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
updateError = _yield$supabase$auth$3.error;
|
|
6019
|
-
if (!(updateError || !(updatedData !== null && updatedData !== void 0 && updatedData.user))) {
|
|
6020
|
-
_context4.next = 4;
|
|
6083
|
+
if (code) {
|
|
6084
|
+
_context3.next = 4;
|
|
6021
6085
|
break;
|
|
6022
6086
|
}
|
|
6023
|
-
return
|
|
6087
|
+
return _context3.abrupt("return", c.json({
|
|
6024
6088
|
success: false,
|
|
6025
|
-
message:
|
|
6026
|
-
});
|
|
6089
|
+
message: i18n.codeRequired
|
|
6090
|
+
}, 200));
|
|
6027
6091
|
case 4:
|
|
6028
|
-
|
|
6029
|
-
|
|
6092
|
+
if (!(!password || password.length < 6)) {
|
|
6093
|
+
_context3.next = 5;
|
|
6094
|
+
break;
|
|
6095
|
+
}
|
|
6096
|
+
return _context3.abrupt("return", c.json({
|
|
6097
|
+
success: false,
|
|
6098
|
+
message: i18n.passwordTooShort
|
|
6099
|
+
}, 200));
|
|
6030
6100
|
case 5:
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6101
|
+
supabase = getSupabase();
|
|
6102
|
+
sessionId = extractSessionIdFromAuthTableName(tableName);
|
|
6103
|
+
_context3.next = 6;
|
|
6104
|
+
return getSessionAdminRowByEmail(supabase, sessionId, account);
|
|
6105
|
+
case 6:
|
|
6106
|
+
adminRow = _context3.sent;
|
|
6107
|
+
if (adminRow !== null && adminRow !== void 0 && adminRow.user_id) {
|
|
6108
|
+
_context3.next = 7;
|
|
6109
|
+
break;
|
|
6110
|
+
}
|
|
6111
|
+
return _context3.abrupt("return", c.json({
|
|
6112
|
+
success: false,
|
|
6113
|
+
message: i18n.userNotFound
|
|
6114
|
+
}, 200));
|
|
6115
|
+
case 7:
|
|
6116
|
+
_context3.next = 8;
|
|
6117
|
+
return verifyCode(account, code);
|
|
6118
|
+
case 8:
|
|
6119
|
+
verifyResult = _context3.sent;
|
|
6120
|
+
if (verifyResult !== null && verifyResult !== void 0 && verifyResult.verified) {
|
|
6121
|
+
_context3.next = 9;
|
|
6034
6122
|
break;
|
|
6035
6123
|
}
|
|
6036
|
-
return
|
|
6124
|
+
return _context3.abrupt("return", c.json({
|
|
6037
6125
|
success: false,
|
|
6038
|
-
message:
|
|
6126
|
+
message: i18n.codeInvalidOrExpired
|
|
6127
|
+
}, 200));
|
|
6128
|
+
case 9:
|
|
6129
|
+
_context3.next = 10;
|
|
6130
|
+
return supabase.auth.admin.updateUserById(adminRow.user_id, {
|
|
6131
|
+
password: password
|
|
6039
6132
|
});
|
|
6040
|
-
case
|
|
6041
|
-
|
|
6133
|
+
case 10:
|
|
6134
|
+
_yield$supabase$auth$2 = _context3.sent;
|
|
6135
|
+
updateError = _yield$supabase$auth$2.error;
|
|
6136
|
+
if (!updateError) {
|
|
6137
|
+
_context3.next = 11;
|
|
6138
|
+
break;
|
|
6139
|
+
}
|
|
6140
|
+
return _context3.abrupt("return", c.json({
|
|
6141
|
+
success: false,
|
|
6142
|
+
message: updateError.message || i18n.resetFailed
|
|
6143
|
+
}, 200));
|
|
6144
|
+
case 11:
|
|
6145
|
+
return _context3.abrupt("return", c.json({
|
|
6042
6146
|
success: true,
|
|
6043
|
-
|
|
6147
|
+
message: i18n.resetSuccess
|
|
6148
|
+
}, 200));
|
|
6149
|
+
case 12:
|
|
6150
|
+
_context3.prev = 12;
|
|
6151
|
+
_t4 = _context3["catch"](0);
|
|
6152
|
+
console.error("重置密码失败:", _t4);
|
|
6153
|
+
_i18n2 = getPasswordResetMessages(c);
|
|
6154
|
+
return _context3.abrupt("return", c.json({
|
|
6155
|
+
success: false,
|
|
6156
|
+
message: _i18n2.resetFailed,
|
|
6157
|
+
error: _t4.message
|
|
6158
|
+
}, 500));
|
|
6159
|
+
case 13:
|
|
6160
|
+
case "end":
|
|
6161
|
+
return _context3.stop();
|
|
6162
|
+
}
|
|
6163
|
+
}, _callee3, null, [[0, 12]]);
|
|
6164
|
+
}));
|
|
6165
|
+
return _resetPassword.apply(this, arguments);
|
|
6166
|
+
}
|
|
6167
|
+
function insertAdminRegistryRow(_x5, _x6, _x7, _x8) {
|
|
6168
|
+
return _insertAdminRegistryRow.apply(this, arguments);
|
|
6169
|
+
}
|
|
6170
|
+
function _insertAdminRegistryRow() {
|
|
6171
|
+
_insertAdminRegistryRow = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(supabase, sessionId, userId, account) {
|
|
6172
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
6173
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
6174
|
+
case 0:
|
|
6175
|
+
_context4.next = 1;
|
|
6176
|
+
return supabase.from("_cms_admin_registry").insert({
|
|
6177
|
+
session_id: normalizeSessionId(sessionId),
|
|
6178
|
+
user_id: userId,
|
|
6179
|
+
email: account
|
|
6044
6180
|
});
|
|
6045
|
-
case
|
|
6181
|
+
case 1:
|
|
6182
|
+
return _context4.abrupt("return", _context4.sent);
|
|
6183
|
+
case 2:
|
|
6046
6184
|
case "end":
|
|
6047
6185
|
return _context4.stop();
|
|
6048
6186
|
}
|
|
6049
6187
|
}, _callee4);
|
|
6050
6188
|
}));
|
|
6051
|
-
return
|
|
6189
|
+
return _insertAdminRegistryRow.apply(this, arguments);
|
|
6052
6190
|
}
|
|
6053
6191
|
function getUserSessionId(user) {
|
|
6054
6192
|
var _user$user_metadata2;
|
|
6055
6193
|
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);
|
|
6056
6194
|
}
|
|
6057
|
-
function getEffectiveRoleForSession(
|
|
6195
|
+
function getEffectiveRoleForSession(_x9, _x0) {
|
|
6058
6196
|
return _getEffectiveRoleForSession.apply(this, arguments);
|
|
6059
6197
|
} // POST - 用户登录
|
|
6060
6198
|
function _getEffectiveRoleForSession() {
|
|
@@ -6091,13 +6229,13 @@ function _getEffectiveRoleForSession() {
|
|
|
6091
6229
|
}));
|
|
6092
6230
|
return _getEffectiveRoleForSession.apply(this, arguments);
|
|
6093
6231
|
}
|
|
6094
|
-
function login(
|
|
6232
|
+
function login(_x1, _x10) {
|
|
6095
6233
|
return _login.apply(this, arguments);
|
|
6096
6234
|
}
|
|
6097
6235
|
// GET - 是否允许注册(首次进入需要创建管理员账号)
|
|
6098
6236
|
function _login() {
|
|
6099
6237
|
_login = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(c, tableName) {
|
|
6100
|
-
var _data$session, body, username, password, supabase, sessionId, email, _yield$supabase$auth$
|
|
6238
|
+
var _data$session, body, username, password, supabase, sessionId, email, _yield$supabase$auth$3, data, error, token, user, role, _t5;
|
|
6101
6239
|
return _regeneratorRuntime.wrap(function (_context6) {
|
|
6102
6240
|
while (1) switch (_context6.prev = _context6.next) {
|
|
6103
6241
|
case 0:
|
|
@@ -6135,9 +6273,9 @@ function _login() {
|
|
|
6135
6273
|
password: password
|
|
6136
6274
|
});
|
|
6137
6275
|
case 4:
|
|
6138
|
-
_yield$supabase$auth$
|
|
6139
|
-
data = _yield$supabase$auth$
|
|
6140
|
-
error = _yield$supabase$auth$
|
|
6276
|
+
_yield$supabase$auth$3 = _context6.sent;
|
|
6277
|
+
data = _yield$supabase$auth$3.data;
|
|
6278
|
+
error = _yield$supabase$auth$3.error;
|
|
6141
6279
|
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))) {
|
|
6142
6280
|
_context6.next = 5;
|
|
6143
6281
|
break;
|
|
@@ -6171,12 +6309,12 @@ function _login() {
|
|
|
6171
6309
|
}, 200));
|
|
6172
6310
|
case 8:
|
|
6173
6311
|
_context6.prev = 8;
|
|
6174
|
-
|
|
6175
|
-
console.error("登录失败:",
|
|
6312
|
+
_t5 = _context6["catch"](0);
|
|
6313
|
+
console.error("登录失败:", _t5);
|
|
6176
6314
|
return _context6.abrupt("return", c.json({
|
|
6177
6315
|
success: false,
|
|
6178
6316
|
message: "登录失败",
|
|
6179
|
-
error:
|
|
6317
|
+
error: _t5.message
|
|
6180
6318
|
}, 500));
|
|
6181
6319
|
case 9:
|
|
6182
6320
|
case "end":
|
|
@@ -6186,13 +6324,13 @@ function _login() {
|
|
|
6186
6324
|
}));
|
|
6187
6325
|
return _login.apply(this, arguments);
|
|
6188
6326
|
}
|
|
6189
|
-
function signupStatus(
|
|
6327
|
+
function signupStatus(_x11, _x12) {
|
|
6190
6328
|
return _signupStatus.apply(this, arguments);
|
|
6191
6329
|
}
|
|
6192
6330
|
// POST - 首次注册管理员(每个 session_id 只允许一个)
|
|
6193
6331
|
function _signupStatus() {
|
|
6194
6332
|
_signupStatus = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(c, tableName) {
|
|
6195
|
-
var supabase, sessionId, ok, row, data,
|
|
6333
|
+
var supabase, sessionId, ok, row, data, _t6;
|
|
6196
6334
|
return _regeneratorRuntime.wrap(function (_context7) {
|
|
6197
6335
|
while (1) switch (_context7.prev = _context7.next) {
|
|
6198
6336
|
case 0:
|
|
@@ -6230,12 +6368,12 @@ function _signupStatus() {
|
|
|
6230
6368
|
}, 200));
|
|
6231
6369
|
case 4:
|
|
6232
6370
|
_context7.prev = 4;
|
|
6233
|
-
|
|
6234
|
-
console.error("获取注册状态失败:",
|
|
6371
|
+
_t6 = _context7["catch"](0);
|
|
6372
|
+
console.error("获取注册状态失败:", _t6);
|
|
6235
6373
|
return _context7.abrupt("return", c.json({
|
|
6236
6374
|
success: false,
|
|
6237
6375
|
message: "获取注册状态失败",
|
|
6238
|
-
error:
|
|
6376
|
+
error: _t6.message
|
|
6239
6377
|
}, 500));
|
|
6240
6378
|
case 5:
|
|
6241
6379
|
case "end":
|
|
@@ -6245,13 +6383,13 @@ function _signupStatus() {
|
|
|
6245
6383
|
}));
|
|
6246
6384
|
return _signupStatus.apply(this, arguments);
|
|
6247
6385
|
}
|
|
6248
|
-
function signup(
|
|
6386
|
+
function signup(_x13, _x14) {
|
|
6249
6387
|
return _signup.apply(this, arguments);
|
|
6250
6388
|
}
|
|
6251
6389
|
// POST - 验证token
|
|
6252
6390
|
function _signup() {
|
|
6253
6391
|
_signup = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(c, tableName) {
|
|
6254
|
-
var _body$
|
|
6392
|
+
var _body$username3, _data$session2, body, account, password, supabase, sessionId, email, ok, existing, _yield$supabase$auth$4, data, error, insertRes, token, user, role, _t7;
|
|
6255
6393
|
return _regeneratorRuntime.wrap(function (_context8) {
|
|
6256
6394
|
while (1) switch (_context8.prev = _context8.next) {
|
|
6257
6395
|
case 0:
|
|
@@ -6260,7 +6398,7 @@ function _signup() {
|
|
|
6260
6398
|
return c.req.json();
|
|
6261
6399
|
case 1:
|
|
6262
6400
|
body = _context8.sent;
|
|
6263
|
-
account = (_body$
|
|
6401
|
+
account = (_body$username3 = body.username) === null || _body$username3 === void 0 ? void 0 : _body$username3.trim();
|
|
6264
6402
|
password = body.password;
|
|
6265
6403
|
if (!(!account || !password)) {
|
|
6266
6404
|
_context8.next = 2;
|
|
@@ -6326,67 +6464,61 @@ function _signup() {
|
|
|
6326
6464
|
}
|
|
6327
6465
|
});
|
|
6328
6466
|
case 8:
|
|
6329
|
-
_yield$supabase$auth$
|
|
6330
|
-
data = _yield$supabase$auth$
|
|
6331
|
-
error = _yield$supabase$auth$
|
|
6467
|
+
_yield$supabase$auth$4 = _context8.sent;
|
|
6468
|
+
data = _yield$supabase$auth$4.data;
|
|
6469
|
+
error = _yield$supabase$auth$4.error;
|
|
6332
6470
|
if (!(error || !(data !== null && data !== void 0 && data.user))) {
|
|
6333
|
-
_context8.next =
|
|
6471
|
+
_context8.next = 9;
|
|
6334
6472
|
break;
|
|
6335
6473
|
}
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
if (promoted.success) {
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
}
|
|
6352
|
-
case 10:
|
|
6353
|
-
return _context8.abrupt("return", c.json({
|
|
6354
|
-
success: true,
|
|
6355
|
-
message: "管理员账号已启用,请登录"
|
|
6356
|
-
}, 200));
|
|
6357
|
-
case 11:
|
|
6474
|
+
console.log("注册失败:", error);
|
|
6475
|
+
// if (isSupabaseUserAlreadyExistsError(error)) {
|
|
6476
|
+
// const promoted = await promoteExistingUserToSessionAdmin(
|
|
6477
|
+
// supabase,
|
|
6478
|
+
// email,
|
|
6479
|
+
// sessionId,
|
|
6480
|
+
// account,
|
|
6481
|
+
// )
|
|
6482
|
+
// if (!promoted.success) {
|
|
6483
|
+
// return c.json({ success: false, message: promoted.message } as ApiResponse, 200)
|
|
6484
|
+
// }
|
|
6485
|
+
// return c.json(
|
|
6486
|
+
// { success: true, message: "管理员账号已启用,请登录" } as ApiResponse,
|
|
6487
|
+
// 200
|
|
6488
|
+
// )
|
|
6489
|
+
// }
|
|
6358
6490
|
return _context8.abrupt("return", c.json({
|
|
6359
6491
|
success: false,
|
|
6360
6492
|
message: (error === null || error === void 0 ? void 0 : error.message) || "注册失败"
|
|
6361
6493
|
}, 200));
|
|
6362
|
-
case
|
|
6494
|
+
case 9:
|
|
6363
6495
|
if ((_data$session2 = data.session) !== null && _data$session2 !== void 0 && _data$session2.access_token) {
|
|
6364
|
-
_context8.next =
|
|
6496
|
+
_context8.next = 10;
|
|
6365
6497
|
break;
|
|
6366
6498
|
}
|
|
6367
6499
|
return _context8.abrupt("return", c.json({
|
|
6368
6500
|
success: true,
|
|
6369
6501
|
message: "注册成功,请完成邮箱验证后登录"
|
|
6370
6502
|
}, 200));
|
|
6371
|
-
case
|
|
6372
|
-
_context8.next =
|
|
6503
|
+
case 10:
|
|
6504
|
+
_context8.next = 11;
|
|
6373
6505
|
return insertAdminRegistryRow(supabase, sessionId, data.user.id, account);
|
|
6374
|
-
case
|
|
6506
|
+
case 11:
|
|
6375
6507
|
insertRes = _context8.sent;
|
|
6376
6508
|
if (!insertRes.error) {
|
|
6377
|
-
_context8.next =
|
|
6509
|
+
_context8.next = 12;
|
|
6378
6510
|
break;
|
|
6379
6511
|
}
|
|
6380
6512
|
return _context8.abrupt("return", c.json({
|
|
6381
6513
|
success: false,
|
|
6382
6514
|
message: "管理员已被创建,请使用已有账号登录"
|
|
6383
6515
|
}, 200));
|
|
6384
|
-
case
|
|
6516
|
+
case 12:
|
|
6385
6517
|
token = data.session.access_token;
|
|
6386
6518
|
user = data.user;
|
|
6387
|
-
_context8.next =
|
|
6519
|
+
_context8.next = 13;
|
|
6388
6520
|
return getEffectiveRoleForSession(user, sessionId);
|
|
6389
|
-
case
|
|
6521
|
+
case 13:
|
|
6390
6522
|
role = _context8.sent;
|
|
6391
6523
|
return _context8.abrupt("return", c.json({
|
|
6392
6524
|
success: true,
|
|
@@ -6401,30 +6533,30 @@ function _signup() {
|
|
|
6401
6533
|
}
|
|
6402
6534
|
}
|
|
6403
6535
|
}, 200));
|
|
6404
|
-
case
|
|
6405
|
-
_context8.prev =
|
|
6406
|
-
|
|
6407
|
-
console.error("注册失败:",
|
|
6536
|
+
case 14:
|
|
6537
|
+
_context8.prev = 14;
|
|
6538
|
+
_t7 = _context8["catch"](0);
|
|
6539
|
+
console.error("注册失败:", _t7);
|
|
6408
6540
|
return _context8.abrupt("return", c.json({
|
|
6409
6541
|
success: false,
|
|
6410
6542
|
message: "注册失败",
|
|
6411
|
-
error:
|
|
6543
|
+
error: _t7.message
|
|
6412
6544
|
}, 500));
|
|
6413
|
-
case
|
|
6545
|
+
case 15:
|
|
6414
6546
|
case "end":
|
|
6415
6547
|
return _context8.stop();
|
|
6416
6548
|
}
|
|
6417
|
-
}, _callee8, null, [[0,
|
|
6549
|
+
}, _callee8, null, [[0, 14]]);
|
|
6418
6550
|
}));
|
|
6419
6551
|
return _signup.apply(this, arguments);
|
|
6420
6552
|
}
|
|
6421
|
-
function verifyAuth(
|
|
6553
|
+
function verifyAuth(_x15, _x16) {
|
|
6422
6554
|
return _verifyAuth.apply(this, arguments);
|
|
6423
6555
|
}
|
|
6424
6556
|
// GET - 获取当前用户信息
|
|
6425
6557
|
function _verifyAuth() {
|
|
6426
6558
|
_verifyAuth = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(c, tableName) {
|
|
6427
|
-
var authHeader, token, supabase, _yield$supabase$auth$
|
|
6559
|
+
var authHeader, token, supabase, _yield$supabase$auth$5, data, error, sessionId, role, decoded, message, responseMessage, _t8, _t9;
|
|
6428
6560
|
return _regeneratorRuntime.wrap(function (_context9) {
|
|
6429
6561
|
while (1) switch (_context9.prev = _context9.next) {
|
|
6430
6562
|
case 0:
|
|
@@ -6445,9 +6577,9 @@ function _verifyAuth() {
|
|
|
6445
6577
|
_context9.next = 2;
|
|
6446
6578
|
return supabase.auth.getUser(token);
|
|
6447
6579
|
case 2:
|
|
6448
|
-
_yield$supabase$auth$
|
|
6449
|
-
data = _yield$supabase$auth$
|
|
6450
|
-
error = _yield$supabase$auth$
|
|
6580
|
+
_yield$supabase$auth$5 = _context9.sent;
|
|
6581
|
+
data = _yield$supabase$auth$5.data;
|
|
6582
|
+
error = _yield$supabase$auth$5.error;
|
|
6451
6583
|
if (!(error || !(data !== null && data !== void 0 && data.user))) {
|
|
6452
6584
|
_context9.next = 3;
|
|
6453
6585
|
break;
|
|
@@ -6474,8 +6606,8 @@ function _verifyAuth() {
|
|
|
6474
6606
|
}));
|
|
6475
6607
|
case 6:
|
|
6476
6608
|
_context9.prev = 6;
|
|
6477
|
-
|
|
6478
|
-
message =
|
|
6609
|
+
_t8 = _context9["catch"](1);
|
|
6610
|
+
message = _t8.message;
|
|
6479
6611
|
responseMessage = message === 'TOKEN_EXPIRED' ? "登录已过期,请重新登录" : "认证信息无效";
|
|
6480
6612
|
return _context9.abrupt("return", c.json({
|
|
6481
6613
|
success: false,
|
|
@@ -6483,12 +6615,12 @@ function _verifyAuth() {
|
|
|
6483
6615
|
}, 200));
|
|
6484
6616
|
case 7:
|
|
6485
6617
|
_context9.prev = 7;
|
|
6486
|
-
|
|
6487
|
-
console.error("验证认证失败:",
|
|
6618
|
+
_t9 = _context9["catch"](0);
|
|
6619
|
+
console.error("验证认证失败:", _t9);
|
|
6488
6620
|
return _context9.abrupt("return", c.json({
|
|
6489
6621
|
success: false,
|
|
6490
6622
|
message: "验证认证失败",
|
|
6491
|
-
error:
|
|
6623
|
+
error: _t9.message
|
|
6492
6624
|
}, 500));
|
|
6493
6625
|
case 8:
|
|
6494
6626
|
case "end":
|
|
@@ -6498,13 +6630,13 @@ function _verifyAuth() {
|
|
|
6498
6630
|
}));
|
|
6499
6631
|
return _verifyAuth.apply(this, arguments);
|
|
6500
6632
|
}
|
|
6501
|
-
function getCurrentUser(
|
|
6633
|
+
function getCurrentUser(_x17, _x18) {
|
|
6502
6634
|
return _getCurrentUser.apply(this, arguments);
|
|
6503
6635
|
}
|
|
6504
6636
|
// 中间件:验证 Supabase JWT token
|
|
6505
6637
|
function _getCurrentUser() {
|
|
6506
6638
|
_getCurrentUser = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee0(c, tableName) {
|
|
6507
|
-
var authHeader, token, supabase, _yield$supabase$auth$
|
|
6639
|
+
var authHeader, token, supabase, _yield$supabase$auth$6, data, error, user, sessionId, role, _t0;
|
|
6508
6640
|
return _regeneratorRuntime.wrap(function (_context0) {
|
|
6509
6641
|
while (1) switch (_context0.prev = _context0.next) {
|
|
6510
6642
|
case 0:
|
|
@@ -6524,9 +6656,9 @@ function _getCurrentUser() {
|
|
|
6524
6656
|
_context0.next = 2;
|
|
6525
6657
|
return supabase.auth.getUser(token);
|
|
6526
6658
|
case 2:
|
|
6527
|
-
_yield$supabase$auth$
|
|
6528
|
-
data = _yield$supabase$auth$
|
|
6529
|
-
error = _yield$supabase$auth$
|
|
6659
|
+
_yield$supabase$auth$6 = _context0.sent;
|
|
6660
|
+
data = _yield$supabase$auth$6.data;
|
|
6661
|
+
error = _yield$supabase$auth$6.error;
|
|
6530
6662
|
if (!(error || !(data !== null && data !== void 0 && data.user))) {
|
|
6531
6663
|
_context0.next = 3;
|
|
6532
6664
|
break;
|
|
@@ -6559,12 +6691,12 @@ function _getCurrentUser() {
|
|
|
6559
6691
|
}, 200));
|
|
6560
6692
|
case 6:
|
|
6561
6693
|
_context0.prev = 6;
|
|
6562
|
-
|
|
6563
|
-
console.error("获取用户信息失败:",
|
|
6694
|
+
_t0 = _context0["catch"](0);
|
|
6695
|
+
console.error("获取用户信息失败:", _t0);
|
|
6564
6696
|
return _context0.abrupt("return", c.json({
|
|
6565
6697
|
success: false,
|
|
6566
6698
|
message: "获取用户信息失败",
|
|
6567
|
-
error:
|
|
6699
|
+
error: _t0.message
|
|
6568
6700
|
}, 500));
|
|
6569
6701
|
case 7:
|
|
6570
6702
|
case "end":
|
|
@@ -6644,7 +6776,7 @@ function requireAuth(handler) {
|
|
|
6644
6776
|
}
|
|
6645
6777
|
}, _callee, null, [[0, 5], [1, 4]]);
|
|
6646
6778
|
}));
|
|
6647
|
-
return function (
|
|
6779
|
+
return function (_x19) {
|
|
6648
6780
|
return _ref.apply(this, arguments);
|
|
6649
6781
|
};
|
|
6650
6782
|
}();
|
|
@@ -7215,10 +7347,26 @@ function createDynamicAuthRoute(app) {
|
|
|
7215
7347
|
var tableName = c.req.param("tableName");
|
|
7216
7348
|
return signup(c, tableName);
|
|
7217
7349
|
});
|
|
7350
|
+
app.post("/auth/password/forgot/:tableName", function (c) {
|
|
7351
|
+
var tableName = c.req.param("tableName");
|
|
7352
|
+
return forgotPassword(c, tableName);
|
|
7353
|
+
});
|
|
7354
|
+
app.post("/auth/password/reset/:tableName", function (c) {
|
|
7355
|
+
var tableName = c.req.param("tableName");
|
|
7356
|
+
return resetPassword(c, tableName);
|
|
7357
|
+
});
|
|
7218
7358
|
app.post("/auth/:tableName/login", function (c) {
|
|
7219
7359
|
var tableName = c.req.param("tableName");
|
|
7220
7360
|
return login(c, tableName);
|
|
7221
7361
|
});
|
|
7362
|
+
app.post("/auth/:tableName/password/forgot", function (c) {
|
|
7363
|
+
var tableName = c.req.param("tableName");
|
|
7364
|
+
return forgotPassword(c, tableName);
|
|
7365
|
+
});
|
|
7366
|
+
app.post("/auth/:tableName/password/reset", function (c) {
|
|
7367
|
+
var tableName = c.req.param("tableName");
|
|
7368
|
+
return resetPassword(c, tableName);
|
|
7369
|
+
});
|
|
7222
7370
|
app.get("/auth/:tableName/current", function (c) {
|
|
7223
7371
|
var tableName = c.req.param("tableName");
|
|
7224
7372
|
return getCurrentUser(c, tableName);
|
|
@@ -7279,5 +7427,5 @@ function createCmsRoutes(app) {
|
|
|
7279
7427
|
return app;
|
|
7280
7428
|
}
|
|
7281
7429
|
|
|
7282
|
-
export { AuthService, getCmsModelService as CmsModel, CmsModelService, DynamicTableService, OssUploadError, OssUploadService, closeSupabase as closeDatabase, closeSupabase, createAuthRoute, createCmsRoutes, createDataRoute, createDynamicAuthRoute, createDynamicDataRoute, createModel, createModelRoute, createOssUploadRoute, createTableData, deleteModel, deleteTableData, dropForeignKeys, executeSupabaseSetup, feishuAlertConfig, getAuthService, getCmsModelService, getCurrentUser, getSupabase as getDatabase, getDynamicTableService, getModels, getOssUploadService, getRelationOptions, getSupabase, getSupabaseSetupSQL, getTableData, getTableDataWithRelations, initializeCmsModel, initializeCmsSystem, initializeSupabase as initializeDatabase, initializeOssUpload, initializeSupabase, login, notifyCmsCrudErrorToFeishu, reportCmsCrudErrorToFeishu, requireAuth, signup, signupStatus, initializeCmsSystem as syncDatabase, testConnection, updateModel, updateTableData, uploadToOss, verifyAuth };
|
|
7430
|
+
export { AuthService, getCmsModelService as CmsModel, CmsModelService, DynamicTableService, OssUploadError, OssUploadService, closeSupabase as closeDatabase, closeSupabase, createAuthRoute, createCmsRoutes, createDataRoute, createDynamicAuthRoute, createDynamicDataRoute, createModel, createModelRoute, createOssUploadRoute, createTableData, deleteModel, deleteTableData, dropForeignKeys, executeSupabaseSetup, feishuAlertConfig, forgotPassword, getAuthService, getCmsModelService, getCurrentUser, getSupabase as getDatabase, getDynamicTableService, getModels, getOssUploadService, getRelationOptions, getSupabase, getSupabaseSetupSQL, getTableData, getTableDataWithRelations, initializeCmsModel, initializeCmsSystem, initializeSupabase as initializeDatabase, initializeOssUpload, initializeSupabase, login, notifyCmsCrudErrorToFeishu, reportCmsCrudErrorToFeishu, requireAuth, resetPassword, signup, signupStatus, initializeCmsSystem as syncDatabase, testConnection, updateModel, updateTableData, uploadToOss, verifyAuth };
|
|
7283
7431
|
//# sourceMappingURL=index.esm.js.map
|