MCPcopy Create free account
hub / github.com/msgbyte/tailchat / resolveToken

Method resolveToken

server/services/core/user/user.service.ts:737–754  ·  view source on GitHub ↗

* 校验JWT的合法性 * @param ctx * @returns

(ctx: PureContext<{ token: string }, any>)

Source from the content-addressed store, hash-verified

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 * 检查授权是否可用

Callers

nothing calls this directly

Calls 4

verifyJWTMethod · 0.95
transformEntityMethod · 0.95
findByIdMethod · 0.80
tFunction · 0.50

Tested by

no test coverage detected