完善产品购买页面,抽取公共组件,优化导航链接

This commit is contained in:
2025-04-08 11:21:58 +08:00
parent a2c18a1be8
commit ba07c79b04
42 changed files with 1481 additions and 666 deletions

View File

@@ -0,0 +1,41 @@
'use client'
import {User} from '@/lib/models'
import {createContext, ReactNode, useEffect, useState} from 'react'
import {getProfile} from '@/actions/auth/auth'
type AuthContentType = {
profile: User | null
refreshProfile: () => Promise<void>
}
export const AuthContext = createContext<AuthContentType>({
profile: null,
refreshProfile: async () => {
throw new Error('Not implemented')
},
})
export type ProfileProviderProps = {
children: ReactNode
}
export default function AuthProvider(props: ProfileProviderProps) {
const [profile, setProfile] = useState<User | null>(null)
const refreshProfile = async () => {
setProfile(await getProfile(true))
}
useEffect(() => {
refreshProfile().then()
}, [])
return (
<AuthContext.Provider value={{
profile, refreshProfile,
}}>
{props.children}
</AuthContext.Provider>
)
}