|
@@ -35,13 +35,13 @@ class LoginService extends CrudService {
|
|
|
const state = uuid();
|
|
|
const key = `free:auth:state:${state}`;
|
|
|
const _roles = [];
|
|
|
- for (const elm of user.roles) {
|
|
|
+ for (const elm of user.role) {
|
|
|
const role = await this.rmodel.findById({ _id: ObjectId(elm) });
|
|
|
if (role) {
|
|
|
_roles.push(role);
|
|
|
}
|
|
|
}
|
|
|
- user.roles = _roles;
|
|
|
+ user.role = _roles;
|
|
|
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, roles, remark, openid }) {
|
|
|
+ async createJwt({ id, name, phone, role, remark, openid }) {
|
|
|
const { secret, expiresIn = '1d', issuer = type } = this.config.jwt;
|
|
|
const subject = phone;
|
|
|
- const res = { uid: id, name, phone, roles, openid, remark };
|
|
|
+ const res = { uid: id, name, phone, role, openid, remark };
|
|
|
const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
|
|
|
return token;
|
|
|
}
|