修复认证循环重定向问题
This commit is contained in:
@@ -7,13 +7,18 @@
|
||||
- 中间件 Limiter
|
||||
- 购买套餐页的冗余组件
|
||||
- 确认各个页面操作列的内容
|
||||
- 提取后刷新提取页套餐可用余量
|
||||
- 首次登录弹窗:需要设置初始密码,展示 实名->购买->提取 的流程介绍
|
||||
- 丰富账单页表格内容与样式
|
||||
- 后台页面:
|
||||
- 提取记录
|
||||
- 使用记录
|
||||
- 登录流程有问题,在人机验证前不允许提交登录请求
|
||||
- 登录流程优化,在人机验证前不允许提交登录请求
|
||||
|
||||
- 账单页面,可以继续完成未支付的订单
|
||||
- 需要先验证订单是否已完成支付
|
||||
- 如果未完成支付,才根据保存的支付链接弹出二维码
|
||||
- 封装二维码组件,如果以后需要调整二维码大小可以快速操作
|
||||
- 弃用 form 组件中 onSubmit 参数,统一使用 handler 参数
|
||||
|
||||
### 下阶段
|
||||
|
||||
|
||||
@@ -174,6 +174,7 @@ async function postCall<R = undefined>(rawResp: Promise<ApiResponse<R>>) {
|
||||
].some(item => item.test(pathname))
|
||||
|
||||
if (match && !resp.success && resp.status === 401) {
|
||||
console.log('🚗🚗🚗🚗🚗 非正常重定向 🚗🚗🚗🚗🚗')
|
||||
redirect('/login?force=true')
|
||||
}
|
||||
|
||||
|
||||
@@ -95,35 +95,35 @@ export default function Extract(props: ExtractProps) {
|
||||
const type = useRef<'copy' | 'open'>('open')
|
||||
const onSubmit = async (values: z.infer<typeof schema>) => {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user