feat(wip): 支持 JWT

This commit is contained in:
xream 2024-10-30 22:51:31 +08:00
parent 542957d34a
commit 2320ab3838
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 26 additions and 6 deletions

View File

@ -30,15 +30,27 @@ export default function register($app) {
),
);
}
const { payload, options } = req.body;
const jwt = eval(`require("jsonwebtoken")`);
res.set('Content-Type', 'application/json;charset=utf-8').send({
token: jwt.sign(
try {
const { payload, options } = req.body;
const jwt = eval(`require("jsonwebtoken")`);
const token = jwt.sign(
payload,
eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH'),
options,
),
});
);
res.set('Content-Type', 'application/json;charset=utf-8').send({
token,
});
} catch (e) {
return failed(
res,
new InternalServerError(
'JWT_SIGN_FAILED',
`Failed to sign JWT token`,
`Reason: ${e.message ?? e}`,
),
);
}
});
// Storage management

View File

@ -24,6 +24,7 @@ if (isLanceX) backend = 'LanceX';
if (isGUIforCores) backend = 'GUI.for.Cores';
let meta = {};
let feature = {};
try {
if (typeof $environment !== 'undefined') {
@ -43,6 +44,12 @@ try {
meta.plugin = $Plugin;
}
if (isNode) {
if (
eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH') &&
eval('process.env.SUB_STORE_FRONTEND_PATH')
) {
feature.share = true;
}
meta.node = {
version: eval('process.version'),
argv: eval('process.argv'),
@ -63,5 +70,6 @@ try {
export default {
backend,
version: substoreVersion,
feature,
meta,
};