fix: me switch me bugs
This commit is contained in:
parent
6021aca4ba
commit
8bfa81842b
@ -113,6 +113,9 @@ export class User extends Model {
|
|||||||
if (this.type === 'org') {
|
if (this.type === 'org') {
|
||||||
if (this.tokenUser && this.tokenUser.uid) {
|
if (this.tokenUser && this.tokenUser.uid) {
|
||||||
id = this.tokenUser.uid;
|
id = this.tokenUser.uid;
|
||||||
|
} else {
|
||||||
|
console.log('getOrgs', 'no uid', this.id, this.username);
|
||||||
|
throw new CustomError('Permission denied');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const cache = await redis.get(`user:${id}:orgs`);
|
const cache = await redis.get(`user:${id}:orgs`);
|
||||||
|
@ -108,13 +108,20 @@ app
|
|||||||
throw new CustomError('username is required');
|
throw new CustomError('username is required');
|
||||||
}
|
}
|
||||||
if (tokenUser.username === username) {
|
if (tokenUser.username === username) {
|
||||||
|
// 自己刷新自己的token
|
||||||
const user = await User.findByPk(tokenUser.id);
|
const user = await User.findByPk(tokenUser.id);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new CustomError('user not found');
|
throw new CustomError('user not found');
|
||||||
}
|
}
|
||||||
const token = await user.createToken();
|
if (user.type === 'user') {
|
||||||
ctx.body = token;
|
const token = await user.createToken();
|
||||||
return;
|
ctx.body = token;
|
||||||
|
return;
|
||||||
|
} else if (user.type === 'org' && tokenUser.uid) {
|
||||||
|
const token = await user.createToken(tokenUser.uid);
|
||||||
|
ctx.body = token;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let me: User;
|
let me: User;
|
||||||
if (tokenUser.uid) {
|
if (tokenUser.uid) {
|
||||||
@ -122,6 +129,10 @@ app
|
|||||||
} else {
|
} else {
|
||||||
me = await User.findByPk(tokenUser.id); // 真实用户
|
me = await User.findByPk(tokenUser.id); // 真实用户
|
||||||
}
|
}
|
||||||
|
if (!me || me.type === 'org') {
|
||||||
|
console.log('switch Error ', me.username, me.type);
|
||||||
|
throw new CustomError('Permission denied');
|
||||||
|
}
|
||||||
if (type === 'user') {
|
if (type === 'user') {
|
||||||
const token = await me.createToken();
|
const token = await me.createToken();
|
||||||
ctx.body = token;
|
ctx.body = token;
|
||||||
@ -129,7 +140,7 @@ app
|
|||||||
}
|
}
|
||||||
const orgUser = await User.findOne({ where: { username } });
|
const orgUser = await User.findOne({ where: { username } });
|
||||||
if (!orgUser) {
|
if (!orgUser) {
|
||||||
throw new CustomError('org not found');
|
throw new CustomError('org user not found');
|
||||||
}
|
}
|
||||||
const user = await Org.findOne({ where: { username } });
|
const user = await Org.findOne({ where: { username } });
|
||||||
const users = user.users;
|
const users = user.users;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user