From 0d90e20ec20f0aeee642756a7ebf9e8514174124 Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期一, 26 十月 2026 21:15:20 +0800
Subject: [PATCH] 微信小程序插件支持
---
src/modules/user/middleware/app.ts | 27 ++++++++++++++++++++++-----
1 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/src/modules/user/middleware/app.ts b/src/modules/user/middleware/app.ts
index 5988fa7..d97cb13 100644
--- a/src/modules/user/middleware/app.ts
+++ b/src/modules/user/middleware/app.ts
@@ -5,6 +5,7 @@
import * as _ from 'lodash';
import { CoolCommException, CoolUrlTagData, TagTypes } from '@cool-midway/core';
import { Utils } from '../../../comm/utils';
+import { UserInfoService } from '../service/info';
/**
* 鐢ㄦ埛
@@ -38,14 +39,30 @@
let { url } = ctx;
url = url.replace(this.prefix, '').split('?')[0];
if (_.startsWith(url, '/app/')) {
- const token = ctx.get('Authorization');
+ let token = ctx.get('Authorization') || '';
+ token = token.replace(/^Bearer\s+/i, '').trim();
try {
ctx.user = jwt.verify(token, this.jwtConfig.secret);
-
- if (ctx.user.isRefresh) {
- throw new CoolCommException('鐧诲綍澶辨晥~');
+ } catch (error) {
+ ctx.user = undefined;
+ if (token) {
+ console.error('[user] token鏃犳晥:', (error as Error).message);
}
- } catch (error) {}
+ }
+ if (ctx.user?.isRefresh) {
+ ctx.user = undefined;
+ } else if (ctx.user?.id) {
+ try {
+ // 浠ょ墝閲岀殑 id 鏄� unionid锛堟墜鏈哄彿鐧诲綍鏃跺氨鏄墜鏈哄彿锛夛紝鏁村瀷 userId 鍒楄鐢ㄧ敤鎴蜂富閿�
+ const userInfoService = await ctx.requestContext.getAsync(
+ UserInfoService
+ );
+ const info = await userInfoService.person(ctx.user.id);
+ if (info?.id) {
+ ctx.user.userId = info.id;
+ }
+ } catch (error) {}
+ }
// 浣跨敤matchUrl鏂规硶鏉ユ鏌RL鏄惁搴旇琚拷鐣�
const isIgnored = this.ignoreUrls.some(pattern =>
this.utils.matchUrl(pattern, url)
--
Gitblit v1.9.1