|
@@ -34,14 +34,14 @@ class LoginService extends CrudService {
|
|
|
// 取出用户的类型,根据用户类型返回相应信息
|
|
|
const state = uuid();
|
|
|
const key = `free:auth:state:${state}`;
|
|
|
- const _roles = [];
|
|
|
- for (const elm of user.role) {
|
|
|
- const role = await this.rmodel.findById({ _id: ObjectId(elm) });
|
|
|
- if (role) {
|
|
|
- _roles.push(role);
|
|
|
+ const _menus = [];
|
|
|
+ for (const elm of user.menus) {
|
|
|
+ const _menu = await this.rmodel.findById({ _id: ObjectId(elm) });
|
|
|
+ if (_menu) {
|
|
|
+ _menus.push(_menu);
|
|
|
}
|
|
|
}
|
|
|
- user.role = _roles;
|
|
|
+ user.menus = _menus;
|
|
|
const token = await this.createJwt(user);
|
|
|
await this.app.redis.set(key, token, 'EX', 60 * 60 * 24);
|
|
|
return { key };
|
|
@@ -55,10 +55,10 @@ class LoginService extends CrudService {
|
|
|
}
|
|
|
|
|
|
// 创建登录Token
|
|
|
- async createJwt({ id, name, phone, role, remark, openid }) {
|
|
|
- const { secret, expiresIn = '1d', issuer = type } = this.config.jwt;
|
|
|
+ async createJwt({ id, name, phone, role, menus, remark, openid }) {
|
|
|
+ const { secret, expiresIn = '1d', issuer = role } = this.config.jwt;
|
|
|
const subject = phone;
|
|
|
- const res = { uid: id, name, phone, role, openid, remark };
|
|
|
+ const res = { uid: id, name, phone, role, menus, openid, remark };
|
|
|
const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
|
|
|
return token;
|
|
|
}
|