私域操盘手 - 移除微信号账号详情的好友列表的包裹层组件,防止标签过多页面变形

This commit is contained in:
柳清爽
2025-05-16 12:03:25 +08:00
parent 1a9a7e8442
commit b8dbd93c89
8 changed files with 162 additions and 490 deletions

46
Cunkebao/hooks/useAuth.ts Normal file
View File

@@ -0,0 +1,46 @@
import { useState, useEffect } from 'react'
export interface AuthState {
isAuthenticated: boolean
isLoading: boolean
user: any | null
}
export function useAuth(): AuthState {
const [state, setState] = useState<AuthState>({
isAuthenticated: false,
isLoading: true,
user: null
})
useEffect(() => {
const checkAuth = async () => {
try {
// 检查本地存储的token
const token = localStorage.getItem('token')
if (!token) {
setState({ isAuthenticated: false, isLoading: false, user: null })
return
}
// TODO: 这里可以添加token验证的API调用
// const response = await validateToken(token)
// if (response.valid) {
// setState({ isAuthenticated: true, isLoading: false, user: response.user })
// } else {
// setState({ isAuthenticated: false, isLoading: false, user: null })
// }
// 临时仅检查token存在性
setState({ isAuthenticated: true, isLoading: false, user: { token } })
} catch (error) {
console.error('Auth check failed:', error)
setState({ isAuthenticated: false, isLoading: false, user: null })
}
}
checkAuth()
}, [])
return state
}