From ff35fb7b4053a5be0c4aca303014a3d076aadba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Sun, 7 Sep 2025 17:38:47 +0800 Subject: [PATCH] fix: fix auth --- src/components/Auth/index.tsx | 8 ++++---- src/pages/detail/index.tsx | 14 +++++++++++++- src/pages/login/index/index.tsx | 1 + src/services/loginService.ts | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/Auth/index.tsx b/src/components/Auth/index.tsx index a78c66b..137e358 100644 --- a/src/components/Auth/index.tsx +++ b/src/components/Auth/index.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react' -import Taro, { useDidShow } from '@tarojs/taro' +import Taro from '@tarojs/taro' import { View } from '@tarojs/components' import { check_login_status } from '@/services/loginService' @@ -10,6 +10,7 @@ export function getCurrentFullPath(): string { const currentPage = pages.at(-1) if (currentPage) { + console.log(currentPage, 'currentPage get') const route = currentPage.route const options = currentPage.options || {} @@ -25,7 +26,6 @@ export function getCurrentFullPath(): string { export default function withAuth

(WrappedComponent: React.ComponentType

) { const ComponentWithAuth: React.FC

= (props: P) => { const [authed, setAuthed] = useState(false) - useEffect(() => { const is_login = check_login_status() setAuthed(is_login) @@ -34,14 +34,14 @@ export default function withAuth

(WrappedComponent: React.Compo const currentPage = getCurrentFullPath() Taro.redirectTo({ url: `/pages/login/index/index${ - currentPage ? `?redirect=${currentPage}` : '' + currentPage ? `?redirect=${encodeURIComponent(currentPage)}` : '' }`, }) } }, []) if (!authed) { - return // 空壳,避免 children 渲染出错 + return // 空壳,避免 children 渲染出错 } return diff --git a/src/pages/detail/index.tsx b/src/pages/detail/index.tsx index 7746b91..dbf2ba2 100644 --- a/src/pages/detail/index.tsx +++ b/src/pages/detail/index.tsx @@ -367,13 +367,25 @@ function Index() { }, ] + function handleBack() { + const pages = Taro.getCurrentPages() + if (pages.length <= 1) { + Taro.redirectTo({ + url: '/pages/list/index', + }) + } else { + Taro.navigateBack() + } + } + + console.log('detail', detail) return ( {/* custom navbar */} - { Taro.navigateBack() }}> + diff --git a/src/pages/login/index/index.tsx b/src/pages/login/index/index.tsx index d00dbf0..6163e3e 100644 --- a/src/pages/login/index/index.tsx +++ b/src/pages/login/index/index.tsx @@ -45,6 +45,7 @@ const LoginPage: React.FC = () => { setTimeout(() => { if (redirect) { + console.log('redirect:', decodeURIComponent(redirect)) Taro.redirectTo({ url: decodeURIComponent(redirect) }); } else { Taro.redirectTo({ url: '/pages/list/index' }); diff --git a/src/services/loginService.ts b/src/services/loginService.ts index 19832fb..e72b175 100644 --- a/src/services/loginService.ts +++ b/src/services/loginService.ts @@ -364,7 +364,7 @@ export const fetchUserProfile = async (): Promise> => // 更新用户信息 export const updateUserProfile = async (payload: Partial) => { try { - const response = await httpService.post('api/user/update', payload); + const response = await httpService.post('/user/update', payload); return response; } catch (error) { console.error('更新用户信息失败:', error);