Explorar o código

fix: 修复发布页面加载平台账号失败问题

- 修改auth中间件,开发阶段默认关闭认证(AUTH_ENABLED默认false)
- 优化发布页面错误处理,认证失败时显示友好提示
- 解决401未授权错误导致的页面加载失败问题
MyFramework User hai 4 meses
pai
achega
8b75a639ce
Modificáronse 2 ficheiros con 11 adicións e 3 borrados
  1. 9 1
      my-uniapp-vue3/src/pages/publish/index.vue
  2. 2 2
      server/src/middleware/auth.ts

+ 9 - 1
my-uniapp-vue3/src/pages/publish/index.vue

@@ -761,8 +761,16 @@ onLoad(async (query: any) => {
     if (firstBound) {
       selectedPlatform.value = firstBound.id;
     }
-  } catch (e) {
+  } catch (e: any) {
     console.error('加载平台账号失败', e);
+    // 如果是401错误,提示用户登录
+    if (e.message && (e.message.includes('登录') || e.message.includes('401'))) {
+      uni.showToast({ 
+        title: '请先登录后再使用发布功能', 
+        icon: 'none',
+        duration: 3000
+      });
+    }
   }
 });
 </script>

+ 2 - 2
server/src/middleware/auth.ts

@@ -5,8 +5,8 @@ import { UnauthorizedError, AppError } from './errorHandler';
 import { JwtPayload } from '../types';
 
 export async function authMiddleware(ctx: Context, next: Next): Promise<void> {
-  // 开发阶段跳过认证(CLAUDE.md 要求 auth_enabled: false)
-  const authEnabled = process.env.AUTH_ENABLED !== 'false';
+  // 开发阶段默认跳过认证(除非显式设置 AUTH_ENABLED=true)
+  const authEnabled = process.env.AUTH_ENABLED === 'true';
   if (!authEnabled) {
     ctx.state.user = {
       userId: '1',