jwt 配置移动到base

This commit is contained in:
ap 2021-06-10 17:16:09 +08:00
parent 5f8036c365
commit e7177e27a6
4 changed files with 18 additions and 14 deletions

View File

@ -12,5 +12,17 @@ export default (app: Application) => {
description: '基础的权限管理功能,包括登录,权限校验', description: '基础的权限管理功能,包括登录,权限校验',
// 中间件 // 中间件
globalMiddlewares: ['baseAuthorityMiddleware', 'baseLogMiddleware'], globalMiddlewares: ['baseAuthorityMiddleware', 'baseLogMiddleware'],
// jwt 生成解密token的
jwt: {
// 注意: 最好重新修改,防止破解
secret: 'FOAPOFALOEQIPNNLQ',
// token
token: {
// 2小时过期需要用刷新token
expire: 2 * 3600,
// 15天内如果没操作过就需要重新登录
refreshExpire: 24 * 3600 * 15,
},
},
} as ModuleConfig; } as ModuleConfig;
}; };

View File

@ -17,6 +17,9 @@ export class BaseAuthorityMiddleware implements IWebMiddleware {
@Config('cool') @Config('cool')
coolConfig: CoolConfig; coolConfig: CoolConfig;
@Config('module.base')
jwtConfig: CoolConfig;
coolCache; coolCache;
@App() @App()
@ -33,7 +36,7 @@ export class BaseAuthorityMiddleware implements IWebMiddleware {
// 路由地址为 admin前缀的 需要权限校验 // 路由地址为 admin前缀的 需要权限校验
if (_.startsWith(url, adminUrl)) { if (_.startsWith(url, adminUrl)) {
try { try {
ctx.admin = jwt.verify(token, this.coolConfig.jwt.secret); ctx.admin = jwt.verify(token, this.jwtConfig.jwt.secret);
} catch (err) {} } catch (err) {}
// 不需要登录 无需权限校验 // 不需要登录 无需权限校验
if (new RegExp(`^${adminUrl}?.*/open/`).test(url)) { if (new RegExp(`^${adminUrl}?.*/open/`).test(url)) {

View File

@ -44,7 +44,7 @@ export class BaseSysLoginService extends BaseService {
@Inject() @Inject()
ctx: Context; ctx: Context;
@Config('cool') @Config('module.base')
coolConfig: CoolConfig; coolConfig: CoolConfig;
/** /**

View File

@ -57,18 +57,7 @@ export default (appInfo: EggAppInfo) => {
}, },
// 单点登录 // 单点登录
sso: false, sso: false,
// jwt 生成解密token的
jwt: {
// 注意: 最好重新修改,防止破解
secret: 'FOAPOFALOEQIPNNLQ',
// token
token: {
// 2小时过期需要用刷新token
expire: 2 * 3600,
// 15天内如果没操作过就需要重新登录
refreshExpire: 24 * 3600 * 15,
},
},
// 分页配置 // 分页配置
page: { page: {
// 分页查询每页条数 // 分页查询每页条数