@proteinjs/user-server 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/dist/generated/index.d.ts +11 -0
  4. package/dist/generated/index.d.ts.map +1 -0
  5. package/dist/generated/index.js +45 -0
  6. package/dist/generated/index.js.map +1 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +21 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/src/authentication/DbSessionStore.d.ts +17 -0
  12. package/dist/src/authentication/DbSessionStore.d.ts.map +1 -0
  13. package/dist/src/authentication/DbSessionStore.js +181 -0
  14. package/dist/src/authentication/DbSessionStore.js.map +1 -0
  15. package/dist/src/authentication/DefaultAdminCredentials.d.ts +12 -0
  16. package/dist/src/authentication/DefaultAdminCredentials.d.ts.map +1 -0
  17. package/dist/src/authentication/DefaultAdminCredentials.js +18 -0
  18. package/dist/src/authentication/DefaultAdminCredentials.js.map +1 -0
  19. package/dist/src/authentication/authenticate.d.ts +6 -0
  20. package/dist/src/authentication/authenticate.d.ts.map +1 -0
  21. package/dist/src/authentication/authenticate.js +79 -0
  22. package/dist/src/authentication/authenticate.js.map +1 -0
  23. package/dist/src/authentication/destroySession.d.ts +2 -0
  24. package/dist/src/authentication/destroySession.d.ts.map +1 -0
  25. package/dist/src/authentication/destroySession.js +58 -0
  26. package/dist/src/authentication/destroySession.js.map +1 -0
  27. package/dist/src/authorization/userCache.d.ts +4 -0
  28. package/dist/src/authorization/userCache.d.ts.map +1 -0
  29. package/dist/src/authorization/userCache.js +70 -0
  30. package/dist/src/authorization/userCache.js.map +1 -0
  31. package/dist/src/routes/createUser.d.ts +3 -0
  32. package/dist/src/routes/createUser.d.ts.map +1 -0
  33. package/dist/src/routes/createUser.js +83 -0
  34. package/dist/src/routes/createUser.js.map +1 -0
  35. package/dist/src/routes/login.d.ts +3 -0
  36. package/dist/src/routes/login.d.ts.map +1 -0
  37. package/dist/src/routes/login.js +76 -0
  38. package/dist/src/routes/login.js.map +1 -0
  39. package/dist/src/routes/logout.d.ts +3 -0
  40. package/dist/src/routes/logout.d.ts.map +1 -0
  41. package/dist/src/routes/logout.js +87 -0
  42. package/dist/src/routes/logout.js.map +1 -0
  43. package/generated/index.ts +41 -0
  44. package/index.ts +2 -0
  45. package/jest.config.js +18 -0
  46. package/package.json +43 -0
  47. package/src/authentication/DbSessionStore.ts +91 -0
  48. package/src/authentication/DefaultAdminCredentials.ts +15 -0
  49. package/src/authentication/authenticate.ts +28 -0
  50. package/src/authentication/destroySession.ts +9 -0
  51. package/src/authorization/userCache.ts +23 -0
  52. package/src/routes/createUser.ts +32 -0
  53. package/src/routes/login.ts +29 -0
  54. package/src/routes/logout.ts +28 -0
  55. package/tsconfig.json +18 -0
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.userCache = void 0;
43
+ var moment_1 = __importDefault(require("moment"));
44
+ var db_1 = require("@proteinjs/db");
45
+ var user_1 = require("@proteinjs/user");
46
+ var DefaultAdminCredentials_1 = require("../authentication/DefaultAdminCredentials");
47
+ exports.userCache = {
48
+ key: user_1.USER_SESSION_CACHE_KEY,
49
+ create: function (sessionId, userEmail) { return __awaiter(void 0, void 0, void 0, function () {
50
+ var user, adminCredentials, adminUser;
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0:
54
+ user = user_1.guestUser;
55
+ if (!userEmail) return [3 /*break*/, 3];
56
+ adminCredentials = DefaultAdminCredentials_1.DefaultAdminCredentials.getCredentials();
57
+ if (!(adminCredentials && userEmail == adminCredentials.username)) return [3 /*break*/, 1];
58
+ adminUser = { name: 'Admin', email: adminCredentials.username, password: adminCredentials.password, emailVerified: true, roles: 'admin', created: (0, moment_1.default)(), updated: (0, moment_1.default)(), id: 'admin' };
59
+ user = adminUser;
60
+ return [3 /*break*/, 3];
61
+ case 1: return [4 /*yield*/, (0, db_1.getSystemDb)().get(user_1.tables.User, { email: userEmail })];
62
+ case 2:
63
+ user = _a.sent();
64
+ _a.label = 3;
65
+ case 3: return [2 /*return*/, user];
66
+ }
67
+ });
68
+ }); }
69
+ };
70
+ //# sourceMappingURL=userCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userCache.js","sourceRoot":"","sources":["../../../src/authorization/userCache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4B;AAE5B,oCAA4C;AAC5C,wCAAkF;AAClF,qFAAoF;AAEvE,QAAA,SAAS,GAA2B;IAC7C,GAAG,EAAE,6BAAsB;IAC3B,MAAM,EAAE,UAAO,SAAiB,EAAE,SAAiB;;;;;oBAC3C,IAAI,GAAG,gBAAS,CAAC;yBACjB,SAAS,EAAT,wBAAS;oBACH,gBAAgB,GAAG,iDAAuB,CAAC,cAAc,EAAE,CAAC;yBAC9D,CAAA,gBAAgB,IAAI,SAAS,IAAI,gBAAgB,CAAC,QAAQ,CAAA,EAA1D,wBAA0D;oBACpD,SAAS,GAAS,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAA,gBAAM,GAAE,EAAE,OAAO,EAAE,IAAA,gBAAM,GAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC;oBACzM,IAAI,GAAG,SAAS,CAAC;;wBAEV,qBAAM,IAAA,gBAAW,GAAE,CAAC,GAAG,CAAC,aAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAA;;oBAAjE,IAAI,GAAG,SAA0D,CAAC;;wBAI1E,sBAAO,IAAI,EAAC;;;SACf;CACJ,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Route } from '@proteinjs/server-api';
2
+ export declare const createUser: Route;
3
+ //# sourceMappingURL=createUser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createUser.d.ts","sourceRoot":"","sources":["../../../src/routes/createUser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAK9C,eAAO,MAAM,UAAU,EAAE,KAyBxB,CAAA"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.createUser = void 0;
43
+ var sha256_1 = __importDefault(require("crypto-js/sha256"));
44
+ var db_1 = require("@proteinjs/db");
45
+ var user_1 = require("@proteinjs/user");
46
+ var util_1 = require("@proteinjs/util");
47
+ exports.createUser = {
48
+ path: user_1.routes.createUser.path,
49
+ method: user_1.routes.createUser.method,
50
+ onRequest: function (request, response) { return __awaiter(void 0, void 0, void 0, function () {
51
+ var logger, user, db, userRecord, error;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ logger = new util_1.Logger('createUser');
56
+ user = request.body;
57
+ db = (0, db_1.getSystemDb)();
58
+ return [4 /*yield*/, db.get(user_1.tables.User, { email: user.email })];
59
+ case 1:
60
+ userRecord = _a.sent();
61
+ if (userRecord) {
62
+ error = "User with this email already exists";
63
+ console.error("".concat(error, ": ").concat(user.email));
64
+ response.send({ error: error });
65
+ return [2 /*return*/];
66
+ }
67
+ return [4 /*yield*/, db.insert(user_1.tables.User, {
68
+ name: user.name,
69
+ email: user.email,
70
+ password: (0, sha256_1.default)(user.password).toString(),
71
+ emailVerified: false,
72
+ roles: '',
73
+ })];
74
+ case 2:
75
+ _a.sent();
76
+ logger.info("Created user: ".concat(user.email));
77
+ response.send({});
78
+ return [2 /*return*/];
79
+ }
80
+ });
81
+ }); }
82
+ };
83
+ //# sourceMappingURL=createUser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createUser.js","sourceRoot":"","sources":["../../../src/routes/createUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAsC;AAEtC,oCAA4C;AAC5C,wCAAuD;AACvD,wCAAyC;AAE5B,QAAA,UAAU,GAAU;IAC7B,IAAI,EAAE,aAAM,CAAC,UAAU,CAAC,IAAI;IAC5B,MAAM,EAAE,aAAM,CAAC,UAAU,CAAC,MAAM;IAChC,SAAS,EAAE,UAAO,OAAO,EAAE,QAAQ;;;;;oBACzB,MAAM,GAAG,IAAI,aAAM,CAAC,YAAY,CAAC,CAAC;oBAClC,IAAI,GAAG,OAAO,CAAC,IAAY,CAAC;oBAC5B,EAAE,GAAG,IAAA,gBAAW,GAAE,CAAC;oBACN,qBAAM,EAAE,CAAC,GAAG,CAAC,aAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,EAAA;;oBAA7D,UAAU,GAAG,SAAgD;oBACnE,IAAI,UAAU,EAAE;wBACN,KAAK,GAAG,qCAAqC,CAAC;wBACpD,OAAO,CAAC,KAAK,CAAC,UAAG,KAAK,eAAK,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC;wBACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;wBACzB,sBAAO;qBACV;oBAED,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAM,CAAC,IAAI,EAAE;4BACzB,IAAI,EAAE,IAAI,CAAC,IAAI;4BACf,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,QAAQ,EAAE,IAAA,gBAAM,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;4BAC1C,aAAa,EAAE,KAAK;4BACpB,KAAK,EAAE,EAAE;yBACZ,CAAC,EAAA;;oBANF,SAME,CAAC;oBACH,MAAM,CAAC,IAAI,CAAC,wBAAiB,IAAI,CAAC,KAAK,CAAE,CAAC,CAAC;oBAC3C,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;;;;SACrB;CACJ,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Route } from '@proteinjs/server-api';
2
+ export declare const login: Route;
3
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/routes/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI9C,eAAO,MAAM,KAAK,EAAE,KAwBnB,CAAA"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.login = void 0;
40
+ var user_1 = require("@proteinjs/user");
41
+ var authenticate_1 = require("../authentication/authenticate");
42
+ exports.login = {
43
+ path: user_1.routes.login.path,
44
+ method: user_1.routes.login.method,
45
+ onRequest: function (request, response) { return __awaiter(void 0, void 0, void 0, function () {
46
+ var credentials, error, result;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0:
50
+ credentials = request.body;
51
+ if (!credentials.email || !credentials.password) {
52
+ error = "Email and password cannot be blank";
53
+ console.error(error);
54
+ response.send({ error: error });
55
+ return [2 /*return*/];
56
+ }
57
+ return [4 /*yield*/, (0, authenticate_1.authenticate)(credentials.email, credentials.password)];
58
+ case 1:
59
+ result = _a.sent();
60
+ if (result !== true) {
61
+ console.error(result);
62
+ response.send({ error: result });
63
+ return [2 /*return*/];
64
+ }
65
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
66
+ request.login(credentials.email, resolve);
67
+ })];
68
+ case 2:
69
+ _a.sent();
70
+ response.send({});
71
+ return [2 /*return*/];
72
+ }
73
+ });
74
+ }); }
75
+ };
76
+ //# sourceMappingURL=login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../../src/routes/login.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wCAAyC;AACzC,+DAA8D;AAEjD,QAAA,KAAK,GAAU;IACxB,IAAI,EAAE,aAAM,CAAC,KAAK,CAAC,IAAI;IACvB,MAAM,EAAE,aAAM,CAAC,KAAK,CAAC,MAAM;IAC3B,SAAS,EAAE,UAAO,OAAY,EAAE,QAAQ;;;;;oBAC9B,WAAW,GAAsC,OAAO,CAAC,IAAI,CAAC;oBACpE,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE;wBACvC,KAAK,GAAG,oCAAoC,CAAC;wBACnD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;wBACzB,sBAAO;qBACV;oBAEc,qBAAM,IAAA,2BAAY,EAAC,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAA;;oBAApE,MAAM,GAAG,SAA2D;oBAC1E,IAAI,MAAM,KAAK,IAAI,EAAE;wBACjB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;wBACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;wBACjC,sBAAO;qBACV;oBAED,qBAAM,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;4BAC9B,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;wBAC9C,CAAC,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;;;;SACrB;CACJ,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Route } from '@proteinjs/server-api';
2
+ export declare const logout: Route;
3
+ //# sourceMappingURL=logout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../src/routes/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI9C,eAAO,MAAM,MAAM,EAAE,KAuBpB,CAAA"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.logout = void 0;
40
+ var user_1 = require("@proteinjs/user");
41
+ var destroySession_1 = require("../authentication/destroySession");
42
+ exports.logout = {
43
+ path: user_1.routes.logout.path,
44
+ method: user_1.routes.logout.method,
45
+ onRequest: function (request, response) { return __awaiter(void 0, void 0, void 0, function () {
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ // request.logout();
50
+ // await request.session.destroy();
51
+ // await new Promise((resolve, reject) => {
52
+ // request.session?.destroy((error: any) => {
53
+ // if (error) {
54
+ // reject(error);
55
+ // return;
56
+ // }
57
+ // resolve();
58
+ // });
59
+ // });
60
+ // delete request._passport?.session?.user;
61
+ // console.info(`request.sessionID: ${request.sessionID}`);
62
+ // console.info(`request.session?.id: ${request.session?.id}`);
63
+ return [4 /*yield*/, (0, destroySession_1.destroySession)(request.sessionID)];
64
+ case 1:
65
+ // request.logout();
66
+ // await request.session.destroy();
67
+ // await new Promise((resolve, reject) => {
68
+ // request.session?.destroy((error: any) => {
69
+ // if (error) {
70
+ // reject(error);
71
+ // return;
72
+ // }
73
+ // resolve();
74
+ // });
75
+ // });
76
+ // delete request._passport?.session?.user;
77
+ // console.info(`request.sessionID: ${request.sessionID}`);
78
+ // console.info(`request.session?.id: ${request.session?.id}`);
79
+ _a.sent();
80
+ request.session.passport.user = null;
81
+ response.redirect('/login');
82
+ return [2 /*return*/];
83
+ }
84
+ });
85
+ }); }
86
+ };
87
+ //# sourceMappingURL=logout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../../src/routes/logout.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wCAAyC;AACzC,mEAAkE;AAErD,QAAA,MAAM,GAAU;IACzB,IAAI,EAAE,aAAM,CAAC,MAAM,CAAC,IAAI;IACxB,MAAM,EAAE,aAAM,CAAC,MAAM,CAAC,MAAM;IAC5B,SAAS,EAAE,UAAO,OAAY,EAAE,QAAQ;;;;gBACpC,oBAAoB;gBACpB,mCAAmC;gBACnC,2CAA2C;gBAC3C,iDAAiD;gBACjD,uBAAuB;gBACvB,6BAA6B;gBAC7B,sBAAsB;gBACtB,YAAY;gBAEZ,qBAAqB;gBACrB,UAAU;gBACV,MAAM;gBACN,2CAA2C;gBAC3C,2DAA2D;gBAC3D,+DAA+D;gBAC/D,qBAAM,IAAA,+BAAc,EAAC,OAAO,CAAC,SAAS,CAAC,EAAA;;oBAfvC,oBAAoB;oBACpB,mCAAmC;oBACnC,2CAA2C;oBAC3C,iDAAiD;oBACjD,uBAAuB;oBACvB,6BAA6B;oBAC7B,sBAAsB;oBACtB,YAAY;oBAEZ,qBAAqB;oBACrB,UAAU;oBACV,MAAM;oBACN,2CAA2C;oBAC3C,2DAA2D;oBAC3D,+DAA+D;oBAC/D,SAAuC,CAAC;oBACxC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;oBACrC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;;;;SAC/B;CACJ,CAAA"}
@@ -0,0 +1,41 @@
1
+ /** Load Dependency Source Graphs */
2
+
3
+ import '@proteinjs/reflection';
4
+ import '@proteinjs/util';
5
+ import '@proteinjs/db';
6
+ import '@proteinjs/server-api';
7
+ import '@proteinjs/user';
8
+ import 'crypto-js';
9
+ import 'express-session';
10
+ import 'moment';
11
+
12
+
13
+ /** Generate Source Graph */
14
+
15
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user-server/DbSessionStore\",\"value\":{\"packageName\":\"@proteinjs/user-server\",\"name\":\"DbSessionStore\",\"filePath\":\"/home/runner/work/user/user/packages/server/src/authentication/DbSessionStore.ts\",\"qualifiedName\":\"@proteinjs/user-server/DbSessionStore\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"TWELVE_HOURS\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":true,\"visibility\":\"private\"},{\"name\":\"get\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"set\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"touch\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"destroy\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"insertOrUpdate\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[{\"name\":\"sessionId\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"session\",\"type\":{\"packageName\":\"\",\"name\":\"Express.SessionData\",\"filePath\":null,\"qualifiedName\":\"/Express.SessionData\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"cb\",\"type\":{\"packageName\":\"\",\"name\":\"(error?: any) => void\",\"filePath\":null,\"qualifiedName\":\"/(error?: any) => void\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"sweep\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]}],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"express-session\",\"name\":\"Store\",\"filePath\":null,\"qualifiedName\":\"express-session/Store\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"express-session/Store\"},{\"v\":\"@proteinjs/user-server/userCache\",\"value\":{\"packageName\":\"@proteinjs/user-server\",\"name\":\"userCache\",\"filePath\":\"/home/runner/work/user/user/packages/server/src/authorization/userCache.ts\",\"qualifiedName\":\"@proteinjs/user-server/userCache\",\"type\":{\"packageName\":\"\",\"name\":\"SessionDataCache<User>\",\"filePath\":null,\"qualifiedName\":\"/SessionDataCache<User>\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"SessionDataCache\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/SessionDataCache\",\"typeParameters\":[\"@proteinjs/user/User\"],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/server-api/SessionDataCache\"},{\"v\":\"@proteinjs/user-server/createUser\",\"value\":{\"packageName\":\"@proteinjs/user-server\",\"name\":\"createUser\",\"filePath\":\"/home/runner/work/user/user/packages/server/src/routes/createUser.ts\",\"qualifiedName\":\"@proteinjs/user-server/createUser\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/server-api/Route\"},{\"v\":\"@proteinjs/user-server/login\",\"value\":{\"packageName\":\"@proteinjs/user-server\",\"name\":\"login\",\"filePath\":\"/home/runner/work/user/user/packages/server/src/routes/login.ts\",\"qualifiedName\":\"@proteinjs/user-server/login\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}},{\"v\":\"@proteinjs/user-server/logout\",\"value\":{\"packageName\":\"@proteinjs/user-server\",\"name\":\"logout\",\"filePath\":\"/home/runner/work/user/user/packages/server/src/routes/logout.ts\",\"qualifiedName\":\"@proteinjs/user-server/logout\",\"type\":{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"typeParameters\":[],\"directParents\":null}]},\"isExported\":true,\"isConst\":true,\"sourceType\":0}}],\"edges\":[{\"v\":\"@proteinjs/user-server/DbSessionStore\",\"w\":\"express-session/Store\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user-server/userCache\",\"w\":\"@proteinjs/server-api/SessionDataCache\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-server/createUser\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-server/login\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"has type\"},{\"v\":\"@proteinjs/user-server/logout\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"has type\"}]}";
16
+
17
+
18
+ /** Generate Source Links */
19
+
20
+ import { DbSessionStore } from '../src/authentication/DbSessionStore';
21
+ import { userCache } from '../src/authorization/userCache';
22
+ import { createUser } from '../src/routes/createUser';
23
+ import { login } from '../src/routes/login';
24
+ import { logout } from '../src/routes/logout';
25
+
26
+ const sourceLinks = {
27
+ '@proteinjs/user-server/DbSessionStore': DbSessionStore,
28
+ '@proteinjs/user-server/userCache': userCache,
29
+ '@proteinjs/user-server/createUser': createUser,
30
+ '@proteinjs/user-server/login': login,
31
+ '@proteinjs/user-server/logout': logout,
32
+ };
33
+
34
+
35
+ /** Load Source Graph and Links */
36
+
37
+ import { SourceRepository } from '@proteinjs/reflection';
38
+ SourceRepository.merge(sourceGraph, sourceLinks);
39
+
40
+
41
+ export * from '../index';
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { createAuthentication } from './src/authentication/authenticate';
2
+ export * from './src/authentication/DbSessionStore';
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ "roots": [
3
+ "<rootDir>/test"
4
+ ],
5
+ "transform": {
6
+ "^.+\\.tsx?$": "ts-jest"
7
+ },
8
+ "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9
+ "moduleFileExtensions": [
10
+ "ts",
11
+ "tsx",
12
+ "js",
13
+ "jsx",
14
+ "json",
15
+ "node"
16
+ ],
17
+ "testEnvironment": "node"
18
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@proteinjs/user-server",
3
+ "version": "1.0.1",
4
+ "description": "User server components",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/proteinjs/user.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/proteinjs/user/issues"
14
+ },
15
+ "homepage": "https://github.com/proteinjs/user#readme",
16
+ "author": "Brent Bahry",
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "clean": "rm -rf dist/ generated/ node_modules/ package-lock.json",
20
+ "build": "reflection-build && tsc",
21
+ "watch": "reflection-watch"
22
+ },
23
+ "dependencies": {
24
+ "@proteinjs/db": "1.0.3",
25
+ "@proteinjs/reflection": "1.0.2",
26
+ "@proteinjs/server-api": "1.0.2",
27
+ "@proteinjs/user": "1.0.1",
28
+ "@proteinjs/util": "1.0.18",
29
+ "crypto-js": "4.0.0",
30
+ "express-session": "1.17.1",
31
+ "moment": "2.29.4"
32
+ },
33
+ "devDependencies": {
34
+ "@proteinjs/reflection-build": "1.0.5",
35
+ "@types/crypto-js": "4.0.1",
36
+ "@types/express-session": "1.17.0",
37
+ "@types/node": "14.0.13",
38
+ "typescript": "5.2.2"
39
+ },
40
+ "main": "./dist/generated/index.js",
41
+ "types": "./dist/generated/index.d.ts",
42
+ "gitHead": "2f28398c42f853d295bab7940948d0fe8d37b5bc"
43
+ }
@@ -0,0 +1,91 @@
1
+ import { Store } from 'express-session';
2
+ import { getSystemDb, QueryBuilderFactory } from '@proteinjs/db';
3
+ import { tables } from '@proteinjs/user';
4
+ import { destroySession } from './destroySession';
5
+
6
+ export class DbSessionStore extends Store {
7
+ private static readonly TWELVE_HOURS = 1000 * 60 * 60 * 12;
8
+
9
+ constructor() {
10
+ super();
11
+ setInterval(this.sweep, DbSessionStore.TWELVE_HOURS);
12
+ }
13
+
14
+ get = (sessionId: string, cb: (error: any, session?: Express.SessionData|null) => void) => {
15
+ (async () => {
16
+ const result = await getSystemDb().get(tables.Session, { sessionId });
17
+ if (!result) {
18
+ cb(null);
19
+ return;
20
+ }
21
+
22
+ return cb(null, JSON.parse(result.session));
23
+ })();
24
+ }
25
+
26
+ set = (sessionId: string, session: Express.SessionData, cb?: (error?: any) => void) => {
27
+ this.insertOrUpdate(sessionId, session, cb);
28
+ }
29
+
30
+ touch = (sessionId: string, session: Express.SessionData, cb?: (error?: any) => void) => {
31
+ this.insertOrUpdate(sessionId, session, cb);
32
+ }
33
+
34
+ /**
35
+ * Does not get called since request.logout is broken
36
+ * See logout.ts
37
+ */
38
+ destroy = (sessionId: string, cb?: (error?: any) => void) => {
39
+ // console.info('in destroy');
40
+ (async () => {
41
+ await destroySession(sessionId);
42
+ if (cb)
43
+ cb();
44
+ })();
45
+ }
46
+
47
+ private async insertOrUpdate(sessionId: string, session: Express.SessionData, cb?: (error?: any) => void): Promise<void> {
48
+ // Only persist authenticated sessions
49
+ if (!session.passport?.user) {
50
+ if (cb)
51
+ cb();
52
+
53
+ return;
54
+ }
55
+
56
+ const sessionRecord = await getSystemDb().get(tables.Session, { sessionId });
57
+ if (sessionRecord) {
58
+ sessionRecord.session = JSON.stringify(session);
59
+ sessionRecord.expires = (<Date>session.cookie.expires);
60
+ sessionRecord.userEmail = session.passport?.user;
61
+ await getSystemDb().update(tables.Session, sessionRecord, { sessionId });
62
+ } else {
63
+ try {
64
+ await getSystemDb().insert(tables.Session, {
65
+ sessionId,
66
+ session: JSON.stringify(session),
67
+ expires: (<Date>session.cookie.expires),
68
+ userEmail: session.passport?.user
69
+ });
70
+ } catch (error) {
71
+ // race condition on insert
72
+ console.error('Failed to create session', error);
73
+ }
74
+ }
75
+
76
+ if (cb)
77
+ cb();
78
+ }
79
+
80
+ private async sweep(): Promise<void> {
81
+ if (!await getSystemDb().tableExists(tables.Session))
82
+ return;
83
+
84
+ console.info(`Sweeping expired sessions`);
85
+ const qb = new QueryBuilderFactory().getQueryBuilder(tables.Session)
86
+ .condition({ field: 'expires', operator: '<=', value: new Date() })
87
+ ;
88
+ const deleteCount = await getSystemDb().delete(tables.Session, qb);
89
+ console.info(`Swept ${deleteCount} expired sessions`);
90
+ }
91
+ }
@@ -0,0 +1,15 @@
1
+ export class DefaultAdminCredentials {
2
+ private static CREDENTIALS: { username: string, password: string } | undefined;
3
+
4
+ static setCredentials(credentials: { username: string, password: string }) {
5
+ if (DefaultAdminCredentials.CREDENTIALS)
6
+ return;
7
+
8
+ DefaultAdminCredentials.CREDENTIALS = credentials;
9
+ }
10
+
11
+
12
+ static getCredentials() {
13
+ return DefaultAdminCredentials.CREDENTIALS;
14
+ }
15
+ }
@@ -0,0 +1,28 @@
1
+ import sha256 from 'crypto-js/sha256';
2
+ import { getSystemDb } from '@proteinjs/db';
3
+ import { tables } from '@proteinjs/user';
4
+ import { DefaultAdminCredentials } from './DefaultAdminCredentials';
5
+
6
+ export function createAuthentication(defaultAdminCredentials?: { username: string, password: string }) {
7
+ if (defaultAdminCredentials)
8
+ DefaultAdminCredentials.setCredentials(defaultAdminCredentials);
9
+
10
+ return authenticate;
11
+ }
12
+
13
+ export async function authenticate(email: string, password: string): Promise<true|string> {
14
+ const defaultAdminCredentials = DefaultAdminCredentials.getCredentials();
15
+ if (defaultAdminCredentials && defaultAdminCredentials.username == email && defaultAdminCredentials.password == password) {
16
+ console.info('Authenitcated default admin user');
17
+ return true;
18
+ }
19
+
20
+ const users = await getSystemDb().query(tables.User, {
21
+ email,
22
+ password: sha256(password).toString()
23
+ });
24
+ if (users.length < 1)
25
+ return 'User name or password incorrect';
26
+
27
+ return true;
28
+ };
@@ -0,0 +1,9 @@
1
+ import { getSystemDb } from '@proteinjs/db';
2
+ import { tables } from '@proteinjs/user';
3
+
4
+ export async function destroySession(sessionId?: string) {
5
+ if (!sessionId)
6
+ return;
7
+
8
+ await getSystemDb().delete(tables.Session, { sessionId });
9
+ }