master
well 2024-10-29 11:59:38 +08:00
parent 5f071b0b07
commit f163da41d6
5 changed files with 74 additions and 27 deletions

View File

@ -0,0 +1,11 @@
'use client';
import { PropsWithChildren } from 'react';
import { logout } from '@/app/actions/logout';
import { Button } from '../ui/button';
export const LogoutButton: React.FC<PropsWithChildren> = ({ children }) => {
return <Button onClick={() => logout()}>{children}</Button>;
};

View File

@ -1,7 +1,16 @@
import { Logo } from './logo';
'use client';
export const Header = () => (
<header className=" tw-flex tw-justify-center tw-items-center tw-pt-6 tw-max-h-24 tw-flex-auto">
<Logo />
</header>
);
import { useSession } from 'next-auth/react';
import { User } from './user';
export const Header = () => {
const sisson = useSession();
console.log(sisson.data?.user?.name, 111);
return (
<header className=" tw-flex tw-flex-row-reverse tw-pt-6 tw-max-h-24 tw-flex-auto">
<User />
</header>
);
};

View File

@ -1,21 +0,0 @@
import Image from 'next/image';
import Link from 'next/link';
import abc from './next.svg';
import $styles from './page.module.css';
export const Logo = () => (
<Link href="/" className={$styles.link}>
<Image
priority
src={abc}
alt="avatar logo"
sizes="100vw"
style={{
width: '100%',
height: 'auto',
}}
/>
</Link>
);

View File

@ -0,0 +1,41 @@
'use client';
import Link from 'next/link';
import { useSession } from 'next-auth/react';
import { useState } from 'react';
import { logout } from '@/app/actions/logout';
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';
import { Button } from '../ui/button';
export const User = () => {
const { data } = useSession();
const [user, setUser] = useState(data.user);
return (
<div className=" tw-flex tw-justify-center tw-items-center tw-space-x-6 tw-mr-36">
{data.user && (
<Avatar className="tw-h-12 tw-w-12">
<AvatarImage width={160} height={160} src={data?.user.image} />
<AvatarFallback>
<p className=""></p>
</AvatarFallback>
</Avatar>
)}
{data?.user?.name ? (
<p className="tw-text-lg tw-font-bold tw-text-white">{data?.user?.name}</p>
) : (
<></>
)}
{data?.user ? (
<Button onClick={() => logout()}>退</Button>
) : (
<Link href="/auth/login">
<p className="tw-text-white"></p>
</Link>
)}
</div>
);
};

View File

@ -0,0 +1,7 @@
'use server';
import { signOut } from '@/auth';
export const logout = async () => {
await signOut();
};