@proteinjs/user-server 1.0.20 → 1.0.21
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/src/authentication/DbSessionStore.js +6 -6
- package/dist/src/authentication/DbSessionStore.js.map +1 -1
- package/dist/src/authentication/authenticate.js +1 -1
- package/dist/src/authentication/authenticate.js.map +1 -1
- package/dist/src/authentication/destroySession.js +1 -1
- package/dist/src/authentication/destroySession.js.map +1 -1
- package/dist/src/authorization/userCache.js +1 -1
- package/dist/src/authorization/userCache.js.map +1 -1
- package/dist/src/routes/createUser.js +1 -1
- package/dist/src/routes/createUser.js.map +1 -1
- package/package.json +3 -3
- package/src/authentication/DbSessionStore.ts +7 -7
- package/src/authentication/authenticate.ts +2 -2
- package/src/authentication/destroySession.ts +2 -2
- package/src/authorization/userCache.ts +2 -2
- package/src/routes/createUser.ts +2 -2
|
@@ -65,7 +65,7 @@ var DbSessionStore = /** @class */ (function (_super) {
|
|
|
65
65
|
var result;
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
67
|
switch (_a.label) {
|
|
68
|
-
case 0: return [4 /*yield*/, (0, db_1.
|
|
68
|
+
case 0: return [4 /*yield*/, (0, db_1.getDbAsSystem)().get(user_1.tables.Session, { sessionId: sessionId })];
|
|
69
69
|
case 1:
|
|
70
70
|
result = _a.sent();
|
|
71
71
|
if (!result) {
|
|
@@ -120,7 +120,7 @@ var DbSessionStore = /** @class */ (function (_super) {
|
|
|
120
120
|
}
|
|
121
121
|
return [2 /*return*/];
|
|
122
122
|
}
|
|
123
|
-
return [4 /*yield*/, (0, db_1.
|
|
123
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().get(user_1.tables.Session, { sessionId: sessionId })];
|
|
124
124
|
case 1:
|
|
125
125
|
sessionRecord = _d.sent();
|
|
126
126
|
if (!sessionRecord) return [3 /*break*/, 6];
|
|
@@ -130,7 +130,7 @@ var DbSessionStore = /** @class */ (function (_super) {
|
|
|
130
130
|
sessionRecord.session = JSON.stringify(session);
|
|
131
131
|
sessionRecord.expires = session.cookie.expires;
|
|
132
132
|
sessionRecord.userEmail = (_b = session.passport) === null || _b === void 0 ? void 0 : _b.user;
|
|
133
|
-
return [4 /*yield*/, (0, db_1.
|
|
133
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().update(user_1.tables.Session, sessionRecord, { sessionId: sessionId })];
|
|
134
134
|
case 3:
|
|
135
135
|
_d.sent();
|
|
136
136
|
return [3 /*break*/, 5];
|
|
@@ -141,7 +141,7 @@ var DbSessionStore = /** @class */ (function (_super) {
|
|
|
141
141
|
case 5: return [3 /*break*/, 9];
|
|
142
142
|
case 6:
|
|
143
143
|
_d.trys.push([6, 8, , 9]);
|
|
144
|
-
return [4 /*yield*/, (0, db_1.
|
|
144
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().insert(user_1.tables.Session, {
|
|
145
145
|
sessionId: sessionId,
|
|
146
146
|
session: JSON.stringify(session),
|
|
147
147
|
expires: session.cookie.expires,
|
|
@@ -169,7 +169,7 @@ var DbSessionStore = /** @class */ (function (_super) {
|
|
|
169
169
|
var qb, deleteCount;
|
|
170
170
|
return __generator(this, function (_a) {
|
|
171
171
|
switch (_a.label) {
|
|
172
|
-
case 0: return [4 /*yield*/, (0, db_1.
|
|
172
|
+
case 0: return [4 /*yield*/, (0, db_1.getDbAsSystem)().tableExists(user_1.tables.Session)];
|
|
173
173
|
case 1:
|
|
174
174
|
if (!(_a.sent())) {
|
|
175
175
|
return [2 /*return*/];
|
|
@@ -178,7 +178,7 @@ var DbSessionStore = /** @class */ (function (_super) {
|
|
|
178
178
|
qb = new db_1.QueryBuilderFactory()
|
|
179
179
|
.getQueryBuilder(user_1.tables.Session)
|
|
180
180
|
.condition({ field: 'expires', operator: '<=', value: new Date() });
|
|
181
|
-
return [4 /*yield*/, (0, db_1.
|
|
181
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().delete(user_1.tables.Session, qb)];
|
|
182
182
|
case 2:
|
|
183
183
|
deleteCount = _a.sent();
|
|
184
184
|
console.info("Swept ".concat(deleteCount, " expired sessions"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbSessionStore.js","sourceRoot":"","sources":["../../../src/authentication/DbSessionStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"DbSessionStore.js","sourceRoot":"","sources":["../../../src/authentication/DbSessionStore.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAwC;AACxC,oCAAmE;AACnE,wCAAyC;AACzC,mDAAkD;AAElD;IAAoC,kCAAK;IAGvC;QAAA,YACE,iBAAO,SAER;QAED,SAAG,GAAG,UAAC,SAAiB,EAAE,EAA8D;YACtF,CAAC;;;;gCACgB,qBAAM,IAAA,kBAAa,GAAE,CAAC,GAAG,CAAC,aAAM,CAAC,OAAO,EAAE,EAAE,SAAS,WAAA,EAAE,CAAC,EAAA;;4BAAjE,MAAM,GAAG,SAAwD;4BACvE,IAAI,CAAC,MAAM,EAAE;gCACX,EAAE,CAAC,IAAI,CAAC,CAAC;gCACT,sBAAO;6BACR;4BAED,sBAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAC;;;iBAC7C,CAAC,EAAE,CAAC;QACP,CAAC,CAAC;QAEF,SAAG,GAAG,UAAC,SAAiB,EAAE,OAA4B,EAAE,EAA0B;YAChF,KAAI,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;QAC9C,CAAC,CAAC;QAEF,WAAK,GAAG,UAAC,SAAiB,EAAE,OAA4B,EAAE,EAA0B;YAClF,KAAI,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE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|
@@ -64,7 +64,7 @@ function authenticate(email, password) {
|
|
|
64
64
|
console.info('Authenitcated default admin user');
|
|
65
65
|
return [2 /*return*/, true];
|
|
66
66
|
}
|
|
67
|
-
return [4 /*yield*/, (0, db_1.
|
|
67
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().query(user_1.tables.User, {
|
|
68
68
|
email: email,
|
|
69
69
|
password: (0, sha256_1.default)(password).toString(),
|
|
70
70
|
})];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/authentication/authenticate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAsC;AACtC,
|
|
1
|
+
{"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../../src/authentication/authenticate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAsC;AACtC,oCAA8C;AAC9C,wCAAyC;AACzC,qEAAoE;AAEpE,SAAgB,oBAAoB,CAAC,uBAAgE;IACnG,IAAI,uBAAuB,EAAE;QAC3B,iDAAuB,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;KACjE;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAND,oDAMC;AAED,SAAsB,YAAY,CAAC,KAAa,EAAE,QAAgB;;;;;;oBAC1D,uBAAuB,GAAG,iDAAuB,CAAC,cAAc,EAAE,CAAC;oBACzE,IACE,uBAAuB;wBACvB,uBAAuB,CAAC,QAAQ,IAAI,KAAK;wBACzC,uBAAuB,CAAC,QAAQ,IAAI,QAAQ,EAC5C;wBACA,OAAO,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;wBACjD,sBAAO,IAAI,EAAC;qBACb;oBAEa,qBAAM,IAAA,kBAAa,GAAE,CAAC,KAAK,CAAC,aAAM,CAAC,IAAI,EAAE;4BACrD,KAAK,OAAA;4BACL,QAAQ,EAAE,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;yBACtC,CAAC,EAAA;;oBAHI,KAAK,GAAG,SAGZ;oBACF,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;wBACpB,sBAAO,iCAAiC,EAAC;qBAC1C;oBAED,sBAAO,IAAI,EAAC;;;;CACb;AApBD,oCAoBC"}
|
|
@@ -47,7 +47,7 @@ function destroySession(sessionId) {
|
|
|
47
47
|
if (!sessionId) {
|
|
48
48
|
return [2 /*return*/];
|
|
49
49
|
}
|
|
50
|
-
return [4 /*yield*/, (0, db_1.
|
|
50
|
+
return [4 /*yield*/, (0, db_1.getDbAsSystem)().delete(user_1.tables.Session, { sessionId: sessionId })];
|
|
51
51
|
case 1:
|
|
52
52
|
_a.sent();
|
|
53
53
|
return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destroySession.js","sourceRoot":"","sources":["../../../src/authentication/destroySession.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"destroySession.js","sourceRoot":"","sources":["../../../src/authentication/destroySession.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA8C;AAC9C,wCAAyC;AAEzC,SAAsB,cAAc,CAAC,SAAkB;;;;;oBACrD,IAAI,CAAC,SAAS,EAAE;wBACd,sBAAO;qBACR;oBAED,qBAAM,IAAA,kBAAa,GAAE,CAAC,MAAM,CAAC,aAAM,CAAC,OAAO,EAAE,EAAE,SAAS,WAAA,EAAE,CAAC,EAAA;;oBAA3D,SAA2D,CAAC;;;;;CAC7D;AAND,wCAMC"}
|
|
@@ -67,7 +67,7 @@ exports.userCache = {
|
|
|
67
67
|
};
|
|
68
68
|
user = adminUser;
|
|
69
69
|
return [3 /*break*/, 3];
|
|
70
|
-
case 1: return [4 /*yield*/, (0, db_1.
|
|
70
|
+
case 1: return [4 /*yield*/, (0, db_1.getDbAsSystem)().get(user_1.tables.User, { email: userEmail })];
|
|
71
71
|
case 2:
|
|
72
72
|
user = _a.sent();
|
|
73
73
|
delete user['password'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userCache.js","sourceRoot":"","sources":["../../../src/authorization/userCache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4B;AAE5B,
|
|
1
|
+
{"version":3,"file":"userCache.js","sourceRoot":"","sources":["../../../src/authorization/userCache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA4B;AAE5B,oCAA8C;AAC9C,wCAAkF;AAClF,qFAAoF;AAEvE,QAAA,SAAS,GAA2B;IAC/C,GAAG,EAAE,6BAAsB;IAC3B,MAAM,EAAE,UAAO,SAAiB,EAAE,SAAiB;;;;;oBAC7C,IAAI,GAAG,gBAAS,CAAC;yBACjB,SAAS,EAAT,wBAAS;oBACL,gBAAgB,GAAG,iDAAuB,CAAC,cAAc,EAAE,CAAC;yBAC9D,CAAA,gBAAgB,IAAI,SAAS,IAAI,gBAAgB,CAAC,QAAQ,CAAA,EAA1D,wBAA0D;oBACtD,SAAS,GAAS;wBACtB,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,gBAAgB,CAAC,QAAQ;wBAChC,QAAQ,EAAE,gBAAgB,CAAC,QAAQ;wBACnC,aAAa,EAAE,IAAI;wBACnB,KAAK,EAAE,OAAO;wBACd,OAAO,EAAE,IAAA,gBAAM,GAAE;wBACjB,OAAO,EAAE,IAAA,gBAAM,GAAE;wBACjB,EAAE,EAAE,OAAO;qBACZ,CAAC;oBACF,IAAI,GAAG,SAAS,CAAC;;wBAEV,qBAAM,IAAA,kBAAa,GAAE,CAAC,GAAG,CAAC,aAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,EAAA;;oBAAnE,IAAI,GAAG,SAA4D,CAAC;oBACpE,OAAQ,IAAY,CAAC,UAAU,CAAC,CAAC;;wBAIrC,sBAAO,IAAI,EAAC;;;SACb;CACF,CAAC"}
|
|
@@ -54,7 +54,7 @@ exports.createUser = {
|
|
|
54
54
|
case 0:
|
|
55
55
|
logger = new util_1.Logger('createUser');
|
|
56
56
|
user = request.body;
|
|
57
|
-
db = (0, db_1.
|
|
57
|
+
db = (0, db_1.getDbAsSystem)();
|
|
58
58
|
return [4 /*yield*/, db.get(user_1.tables.User, { email: user.email })];
|
|
59
59
|
case 1:
|
|
60
60
|
userRecord = _a.sent();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUser.js","sourceRoot":"","sources":["../../../src/routes/createUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAsC;AAEtC,
|
|
1
|
+
{"version":3,"file":"createUser.js","sourceRoot":"","sources":["../../../src/routes/createUser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAsC;AAEtC,oCAA8C;AAC9C,wCAAuD;AACvD,wCAAyC;AAE5B,QAAA,UAAU,GAAU;IAC/B,IAAI,EAAE,aAAM,CAAC,UAAU,CAAC,IAAI;IAC5B,MAAM,EAAE,aAAM,CAAC,UAAU,CAAC,MAAM;IAChC,SAAS,EAAE,UAAO,OAAO,EAAE,QAAQ;;;;;oBAC3B,MAAM,GAAG,IAAI,aAAM,CAAC,YAAY,CAAC,CAAC;oBAClC,IAAI,GAAG,OAAO,CAAC,IAAY,CAAC;oBAC5B,EAAE,GAAG,IAAA,kBAAa,GAAE,CAAC;oBACR,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;wBACR,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;qBACR;oBAED,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAM,CAAC,IAAI,EAAE;4BAC3B,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;yBACV,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;;;;SACnB;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proteinjs/user-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "User server components",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"watch": "reflection-watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@proteinjs/db": "1.0.
|
|
24
|
+
"@proteinjs/db": "1.0.25",
|
|
25
25
|
"@proteinjs/reflection": "1.1.5",
|
|
26
26
|
"@proteinjs/server-api": "1.3.0",
|
|
27
|
-
"@proteinjs/user": "^1.0.
|
|
27
|
+
"@proteinjs/user": "^1.0.21",
|
|
28
28
|
"@proteinjs/util": "1.1.2",
|
|
29
29
|
"crypto-js": "4.0.0",
|
|
30
30
|
"express-session": "1.17.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Store } from 'express-session';
|
|
2
|
-
import {
|
|
2
|
+
import { getDbAsSystem, QueryBuilderFactory } from '@proteinjs/db';
|
|
3
3
|
import { tables } from '@proteinjs/user';
|
|
4
4
|
import { destroySession } from './destroySession';
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ export class DbSessionStore extends Store {
|
|
|
13
13
|
|
|
14
14
|
get = (sessionId: string, cb: (error: any, session?: Express.SessionData | null) => void) => {
|
|
15
15
|
(async () => {
|
|
16
|
-
const result = await
|
|
16
|
+
const result = await getDbAsSystem().get(tables.Session, { sessionId });
|
|
17
17
|
if (!result) {
|
|
18
18
|
cb(null);
|
|
19
19
|
return;
|
|
@@ -59,19 +59,19 @@ export class DbSessionStore extends Store {
|
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const sessionRecord = await
|
|
62
|
+
const sessionRecord = await getDbAsSystem().get(tables.Session, { sessionId });
|
|
63
63
|
if (sessionRecord) {
|
|
64
64
|
try {
|
|
65
65
|
sessionRecord.session = JSON.stringify(session);
|
|
66
66
|
sessionRecord.expires = <Date>session.cookie.expires;
|
|
67
67
|
sessionRecord.userEmail = session.passport?.user;
|
|
68
|
-
await
|
|
68
|
+
await getDbAsSystem().update(tables.Session, sessionRecord, { sessionId });
|
|
69
69
|
} catch (error) {
|
|
70
70
|
console.error('Failed to update session', error);
|
|
71
71
|
}
|
|
72
72
|
} else {
|
|
73
73
|
try {
|
|
74
|
-
await
|
|
74
|
+
await getDbAsSystem().insert(tables.Session, {
|
|
75
75
|
sessionId,
|
|
76
76
|
session: JSON.stringify(session),
|
|
77
77
|
expires: <Date>session.cookie.expires,
|
|
@@ -89,7 +89,7 @@ export class DbSessionStore extends Store {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
private async sweep(): Promise<void> {
|
|
92
|
-
if (!(await
|
|
92
|
+
if (!(await getDbAsSystem().tableExists(tables.Session))) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -97,7 +97,7 @@ export class DbSessionStore extends Store {
|
|
|
97
97
|
const qb = new QueryBuilderFactory()
|
|
98
98
|
.getQueryBuilder(tables.Session)
|
|
99
99
|
.condition({ field: 'expires', operator: '<=', value: new Date() });
|
|
100
|
-
const deleteCount = await
|
|
100
|
+
const deleteCount = await getDbAsSystem().delete(tables.Session, qb);
|
|
101
101
|
console.info(`Swept ${deleteCount} expired sessions`);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import sha256 from 'crypto-js/sha256';
|
|
2
|
-
import {
|
|
2
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
3
3
|
import { tables } from '@proteinjs/user';
|
|
4
4
|
import { DefaultAdminCredentials } from './DefaultAdminCredentials';
|
|
5
5
|
|
|
@@ -22,7 +22,7 @@ export async function authenticate(email: string, password: string): Promise<tru
|
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const users = await
|
|
25
|
+
const users = await getDbAsSystem().query(tables.User, {
|
|
26
26
|
email,
|
|
27
27
|
password: sha256(password).toString(),
|
|
28
28
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
2
2
|
import { tables } from '@proteinjs/user';
|
|
3
3
|
|
|
4
4
|
export async function destroySession(sessionId?: string) {
|
|
@@ -6,5 +6,5 @@ export async function destroySession(sessionId?: string) {
|
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
await
|
|
9
|
+
await getDbAsSystem().delete(tables.Session, { sessionId });
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
2
|
import { SessionDataCache } from '@proteinjs/server-api';
|
|
3
|
-
import {
|
|
3
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
4
4
|
import { User, tables, guestUser, USER_SESSION_CACHE_KEY } from '@proteinjs/user';
|
|
5
5
|
import { DefaultAdminCredentials } from '../authentication/DefaultAdminCredentials';
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@ export const userCache: SessionDataCache<User> = {
|
|
|
23
23
|
};
|
|
24
24
|
user = adminUser;
|
|
25
25
|
} else {
|
|
26
|
-
user = await
|
|
26
|
+
user = await getDbAsSystem().get(tables.User, { email: userEmail });
|
|
27
27
|
delete (user as any)['password'];
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/routes/createUser.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sha256 from 'crypto-js/sha256';
|
|
2
2
|
import { Route } from '@proteinjs/server-api';
|
|
3
|
-
import {
|
|
3
|
+
import { getDbAsSystem } from '@proteinjs/db';
|
|
4
4
|
import { User, tables, routes } from '@proteinjs/user';
|
|
5
5
|
import { Logger } from '@proteinjs/util';
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ export const createUser: Route = {
|
|
|
10
10
|
onRequest: async (request, response): Promise<void> => {
|
|
11
11
|
const logger = new Logger('createUser');
|
|
12
12
|
const user = request.body as User;
|
|
13
|
-
const db =
|
|
13
|
+
const db = getDbAsSystem();
|
|
14
14
|
const userRecord = await db.get(tables.User, { email: user.email });
|
|
15
15
|
if (userRecord) {
|
|
16
16
|
const error = `User with this email already exists`;
|