Skip to content

Commit 2320ab3

Browse files
committed
feat(wip): 支持 JWT
1 parent 542957d commit 2320ab3

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

backend/src/restful/miscs.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,27 @@ export default function register($app) {
3030
),
3131
);
3232
}
33-
const { payload, options } = req.body;
34-
const jwt = eval(`require("jsonwebtoken")`);
35-
res.set('Content-Type', 'application/json;charset=utf-8').send({
36-
token: jwt.sign(
33+
try {
34+
const { payload, options } = req.body;
35+
const jwt = eval(`require("jsonwebtoken")`);
36+
const token = jwt.sign(
3737
payload,
3838
eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH'),
3939
options,
40-
),
41-
});
40+
);
41+
res.set('Content-Type', 'application/json;charset=utf-8').send({
42+
token,
43+
});
44+
} catch (e) {
45+
return failed(
46+
res,
47+
new InternalServerError(
48+
'JWT_SIGN_FAILED',
49+
`Failed to sign JWT token`,
50+
`Reason: ${e.message ?? e}`,
51+
),
52+
);
53+
}
4254
});
4355

4456
// Storage management

backend/src/utils/env.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if (isLanceX) backend = 'LanceX';
2424
if (isGUIforCores) backend = 'GUI.for.Cores';
2525

2626
let meta = {};
27+
let feature = {};
2728

2829
try {
2930
if (typeof $environment !== 'undefined') {
@@ -43,6 +44,12 @@ try {
4344
meta.plugin = $Plugin;
4445
}
4546
if (isNode) {
47+
if (
48+
eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH') &&
49+
eval('process.env.SUB_STORE_FRONTEND_PATH')
50+
) {
51+
feature.share = true;
52+
}
4653
meta.node = {
4754
version: eval('process.version'),
4855
argv: eval('process.argv'),
@@ -63,5 +70,6 @@ try {
6370
export default {
6471
backend,
6572
version: substoreVersion,
73+
feature,
6674
meta,
6775
};

0 commit comments

Comments
 (0)