You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
563 B
JavaScript

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()
}