From 52c0184482c058ac20212b1eca1062cb158b9015 Mon Sep 17 00:00:00 2001 From: luorijun Date: Mon, 12 May 2025 10:58:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A4=E8=AF=81=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E9=87=8D=E5=AE=9A=E5=90=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 +++- src/actions/base.ts | 1 + src/components/composites/extract/index.tsx | 52 ++++++++++----------- src/middleware.ts | 33 +++++++------ 4 files changed, 50 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 5d3a881..05cc069 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,18 @@ - 中间件 Limiter - 购买套餐页的冗余组件 - 确认各个页面操作列的内容 -- 提取后刷新提取页套餐可用余量 - 首次登录弹窗:需要设置初始密码,展示 实名->购买->提取 的流程介绍 - 丰富账单页表格内容与样式 - 后台页面: - 提取记录 - 使用记录 -- 登录流程有问题,在人机验证前不允许提交登录请求 +- 登录流程优化,在人机验证前不允许提交登录请求 + +- 账单页面,可以继续完成未支付的订单 + - 需要先验证订单是否已完成支付 + - 如果未完成支付,才根据保存的支付链接弹出二维码 +- 封装二维码组件,如果以后需要调整二维码大小可以快速操作 +- 弃用 form 组件中 onSubmit 参数,统一使用 handler 参数 ### 下阶段 diff --git a/src/actions/base.ts b/src/actions/base.ts index 4f4d5ba..1f0ea6d 100644 --- a/src/actions/base.ts +++ b/src/actions/base.ts @@ -174,6 +174,7 @@ async function postCall(rawResp: Promise>) { ].some(item => item.test(pathname)) if (match && !resp.success && resp.status === 401) { + console.log('🚗🚗🚗🚗🚗 非正常重定向 🚗🚗🚗🚗🚗') redirect('/login?force=true') } diff --git a/src/components/composites/extract/index.tsx b/src/components/composites/extract/index.tsx index e771272..b29f0b4 100644 --- a/src/components/composites/extract/index.tsx +++ b/src/components/composites/extract/index.tsx @@ -95,35 +95,35 @@ export default function Extract(props: ExtractProps) { const type = useRef<'copy' | 'open'>('open') const onSubmit = async (values: z.infer) => { switch (type.current) { - case 'copy': - const url = new URL(window.location.href).origin - const text = `${url}${params}` + case 'copy': + const url = new URL(window.location.href).origin + const text = `${url}${params}` - // 使用 clipboard API 复制链接 - let copied = false - try { - await navigator.clipboard.writeText(text) - copied = true - } - catch (e) { - console.log('剪贴板 API 调用失败,尝试备选方案') - } + // 使用 clipboard API 复制链接 + let copied = false + try { + await navigator.clipboard.writeText(text) + copied = true + } + catch (e) { + console.log('剪贴板 API 调用失败,尝试备选方案') + } - // 使用 document.execCommand 作为备选方案 - if (!copied) { - const textarea = document.createElement('textarea') - textarea.value = text - document.body.appendChild(textarea) - textarea.select() - document.execCommand('copy') - document.body.removeChild(textarea) - } + // 使用 document.execCommand 作为备选方案 + if (!copied) { + const textarea = document.createElement('textarea') + textarea.value = text + document.body.appendChild(textarea) + textarea.select() + document.execCommand('copy') + document.body.removeChild(textarea) + } - toast.success('链接已复制到剪贴板') - break - case 'open': - window.open(params, '_blank') - break + toast.success('链接已复制到剪贴板') + break + case 'open': + window.open(params, '_blank') + break } } diff --git a/src/middleware.ts b/src/middleware.ts index b6cd331..751b655 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -28,24 +28,23 @@ export async function middleware(request: NextRequest) { console.log('❌ 刷新访问令牌失败', e) } - // 如果刷新访问令牌成功,则继续访问之前的页面 - const isLogin = request.nextUrl.pathname === '/login' - const redirect = request.nextUrl.searchParams.get('redirect') - if (isLogin && redirect) { - console.log('redirect to', redirect) - return NextResponse.redirect(`${request.nextUrl.origin}${redirect}`) + // 验证访问令牌 + if (request.cookies.get('auth_token')) { + + // 如果刷新访问令牌成功,则继续访问之前的页面 + const isLogin = request.nextUrl.pathname === '/login' + const hasRedirect = request.nextUrl.searchParams.get('redirect') + if (isLogin && hasRedirect) { + return NextResponse.redirect(`${request.nextUrl.origin}${hasRedirect}`) + } } - - // 没有访问令牌不允许访问 admin 页面 - const isAdmin = [ - RegExp(`^/admin.*`), - ].some(item => item.test(request.nextUrl.pathname)) - - const accessToken = request.cookies.get('auth_token') - - if (isAdmin && !accessToken) { - console.log('🚗🚗🚗🚗🚗 非正常重定向 🚗🚗🚗🚗🚗') - return NextResponse.redirect(`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`) + else { + + // 没有访问令牌不允许访问 admin 页面 + const isAdmin = request.nextUrl.pathname.startsWith('/admin') + if (isAdmin) { + return NextResponse.redirect(`${request.nextUrl.origin}/login?redirect=${request.nextUrl.pathname}`) + } } return NextResponse.next({request})