Skip to content

Commit

Permalink
🏷️ fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
miicolas committed Jul 29, 2024
1 parent 020674a commit 291bbcc
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
11 changes: 4 additions & 7 deletions src/components/cards/cardBlog.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { Button } from "@/components/ui/button";
import Link from "next/link";
import getSession from "@/lib/session";
import { Session, CardBlogProps } from "@/lib/types";



type CardBlogProps = {
title: string;
description: string;
date: string;
slug: string;
};

export default async function CardBlog({
title,
description,
date,
slug,
}: CardBlogProps) {
const session = await getSession();
const session: Session = await getSession();

return (
<>
Expand Down
47 changes: 23 additions & 24 deletions src/components/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@ import { Avatar, AvatarImage } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import Link from "next/link";
import getSession from "@/lib/session";


import { Session } from "@/lib/types";

export default async function Header() {
const session = await getSession();
const session: Session = await getSession();
return (
<header className="flex flex-row justify-between items-center">
<h1 className="text-2xl font-bold">Weekly Journal Nicolas'</h1>
<div className="flex flex-row gap-4">
{!session && (
<LoginGithubButton />
)}
{!session && (
<LoginGithubButton />
)}

{session && (
<>
<div className="flex flex-row gap-4">
<Avatar className="border-2 border-gray-200">
<AvatarImage src={session.user.image} />
</Avatar>
<LogoutButton />
{session.user.isAdmin && (
<Link href="/blog/create">
<Button>
Add Post
</Button>
</Link>
)}
</div>
</>
)}
{session && (
<>
<div className="flex flex-row gap-4">
<Avatar className="border-2 border-gray-200">
<AvatarImage src={session?.user?.image} />
</Avatar>
<LogoutButton />
{session?.user?.isAdmin && (
<Link href="/blog/create">
<Button>
Add Post
</Button>
</Link>
)}
</div>
</>
)}
</div>
</header>
);
}
}
6 changes: 4 additions & 2 deletions src/lib/session.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { auth } from "@/lib/auth"
import { User } from "next-auth";
import { Session } from "@/lib/types";

export default async function getSession() {
export default async function getSession(): Promise<Session> {
const session = await auth()

return session
}
16 changes: 16 additions & 0 deletions src/lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// types.d.ts or in your component file
export type User = {
isAdmin?: boolean;
image?: string;
};

export type Session = {
user?: User;
};

export type CardBlogProps = {
title: string;
description: string;
date: string;
slug: string;
};

0 comments on commit 291bbcc

Please sign in to comment.