添加分页功能、打包优化、ts编译优化

This commit is contained in:
周炽键
2021-07-23 21:34:47 +08:00
parent fd85fcef74
commit 6a1f9a3f6b
15 changed files with 3340 additions and 141 deletions

34
middlewares/auth.js Normal file
View File

@@ -0,0 +1,34 @@
const AuthUtils = require('../utils/auth')
const { Account } = require('../entity/account')
const { getManager } = require('typeorm')
module.exports = async function (req,res,next) {
try{
const session = req.cookies.IM_SESS
if(!session) return res.error('未登录',401)
try{
var payload = AuthUtils.decode(session)
}catch(err) {
return res.error(err.message,401)
}
req.auth_session = payload
const manager = getManager()
const detail = await manager.findOne(Account,{ aid:payload.aid })
if(!detail.isActive) return res.error('账号不可用',403)
req.account_detail = detail
}catch(err) {
console.error('登录认证中间件报错:',err);
return res.error('登录凭证已过期',401)
}
next()
}

27
middlewares/page_auth.js Normal file
View File

@@ -0,0 +1,27 @@
const AuthUtils = require('../utils/auth')
const { Account } = require('../entity/account')
const { getManager } = require('typeorm')
module.exports = async function (req,res,next) {
const session = req.cookies.IM_SESS
if(!session) return res.redirect('/oauth/login')
try{
var payload = AuthUtils.decode(session)
}catch(err) {
return res.redirect('/oauth/login')
}
req.auth_session = payload
const manager = getManager()
const detail = await manager.findOne(Account,{ aid:payload.aid })
req.account_detail = detail
next()
}