* 校验JWT的合法性 * @param ctx * @returns
(ctx: PureContext<{ token: string }, any>)
| 735 | * @returns |
| 736 | */ |
| 737 | async resolveToken(ctx: PureContext<{ token: string }, any>) { |
| 738 | const decoded = await this.verifyJWT(ctx.params.token); |
| 739 | const t = ctx.meta.t; |
| 740 | |
| 741 | if (typeof decoded._id !== 'string') { |
| 742 | // token 中没有 _id |
| 743 | throw new EntityError(t('Token 内容不正确')); |
| 744 | } |
| 745 | const doc = await this.adapter.model.findById(decoded._id); |
| 746 | const user: User = await this.transformDocuments(ctx, {}, doc); |
| 747 | |
| 748 | if (user.banned === true) { |
| 749 | throw new BannedError(t('用户被封禁')); |
| 750 | } |
| 751 | |
| 752 | const json = await this.transformEntity(user, true, ctx.meta.token); |
| 753 | return json; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * 检查授权是否可用 |
nothing calls this directly
no test coverage detected