添加 自动刷新Token功能以维持登录状态
This commit is contained in:
31
Server/src/APIs/Console/GetLoginStatus.ts
Normal file
31
Server/src/APIs/Console/GetLoginStatus.ts
Normal 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;
|
||||
@@ -25,6 +25,7 @@ import DelResource from '../APIs/Console/DelResource'
|
||||
import SaveBlog from '../APIs/Console/SaveBlog'
|
||||
import DelBlog from '../APIs/Console/DelBlog'
|
||||
import GetOSSToken from "../APIs/Console/GetOSSToken";
|
||||
import GetLoginStatus from "../APIs/Console/GetLoginStatus";
|
||||
|
||||
class Server {
|
||||
private logger = new Logger('Server');
|
||||
@@ -56,6 +57,7 @@ class Server {
|
||||
this.apiLoader.add(SetBlogPasswd);
|
||||
this.apiLoader.add(DelBlog);
|
||||
this.apiLoader.add(GetOSSToken);
|
||||
this.apiLoader.add(GetLoginStatus);
|
||||
|
||||
this.apiLoader.start(config.apiPort);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user