完善登录与状态回显处理
This commit is contained in:
54
src/app/(root)/@header/_server/user-center.tsx
Normal file
54
src/app/(root)/@header/_server/user-center.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import Link from 'next/link'
|
||||
import {cookies} from 'next/headers'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {AuthContext} from '@/lib/auth'
|
||||
|
||||
export type UserCenterProps = {}
|
||||
|
||||
export default async function UserCenter(props: UserCenterProps) {
|
||||
|
||||
const store = await cookies()
|
||||
const info = store.get('auth_info')?.value
|
||||
const data = info ? JSON.parse(info) as AuthContext : undefined
|
||||
|
||||
return (
|
||||
<div className={`flex items-center`}>
|
||||
{data == undefined
|
||||
? <>
|
||||
<Link
|
||||
href="/login"
|
||||
className={`w-24 h-12 flex items-center justify-center lg:text-lg`}
|
||||
>
|
||||
<span>登录</span>
|
||||
</Link>
|
||||
<Link
|
||||
href="/login"
|
||||
className={[
|
||||
`w-20 lg:w-24 h-10 lg:h-12 bg-gradient-to-r rounded-sm flex items-center justify-center lg:text-lg text-white`,
|
||||
`transition-colors duration-200 ease-in-out`,
|
||||
`from-blue-500 to-cyan-400 hover:from-blue-500 hover:to-cyan-300`,
|
||||
].join(' ')}
|
||||
>
|
||||
<span>注册</span>
|
||||
</Link>
|
||||
</>
|
||||
: <>
|
||||
<Button>
|
||||
进入控制台
|
||||
</Button>
|
||||
{/* profile */}
|
||||
<div>
|
||||
<img
|
||||
src={data.payload.avatar}
|
||||
alt="User Avatar"
|
||||
className="w-10 h-10 rounded-full"
|
||||
/>
|
||||
<p>
|
||||
{data.payload.name}
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user