添加 自动刷新Token功能以维持登录状态

This commit is contained in:
2024-10-16 21:49:04 +08:00
parent 87977298e9
commit 923f499709
3 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { API, RequestData } from "../../Plugs/API/API";
import ServerStdResponse from "../../ServerStdResponse";
import MySQLConnection from '../../Plugs/MySQLConnection'
import Auth from "../../Plugs/Middleware/Auth";
import jwt from "jsonwebtoken";
import config from "../../config";
// 获取登录状态
class GetLoginStatus extends API {
constructor() {
super('GET', '/console/loginStatus', Auth);
}
public async onRequset(data: RequestData, res: any) {
const { uuid } = data._jwt;
const jwtPayload = {
uuid,
loginTime: Date.now()
}
const token = jwt.sign(jwtPayload, config.jwt.secret, { expiresIn: config.jwt.expiresIn });
return res.json({
...ServerStdResponse.OK,
data: {
token
}
});
}
}
export default GetLoginStatus;