fix: fix auth

This commit is contained in:
2025-09-07 17:38:47 +08:00
parent 81340c6e8a
commit ff35fb7b40
4 changed files with 19 additions and 6 deletions

View File

@@ -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<P extends object>(WrappedComponent: React.ComponentType<P>) {
const ComponentWithAuth: React.FC<P> = (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<P extends object>(WrappedComponent: React.Compo
const currentPage = getCurrentFullPath()
Taro.redirectTo({
url: `/pages/login/index/index${
currentPage ? `?redirect=${currentPage}` : ''
currentPage ? `?redirect=${encodeURIComponent(currentPage)}` : ''
}`,
})
}
}, [])
if (!authed) {
return <View /> // 空壳,避免 children 渲染出错
return <View style={{ width: '100vh', height: '100vw', backgroundColor: 'white', position: 'fixed', top: 0, left: 0, zIndex: 999 }} /> // 空壳,避免 children 渲染出错
}
return <WrappedComponent {...props} />