From 3556ac5879b6c22419d899bac9a994b25a745a5c Mon Sep 17 00:00:00 2001 From: Oyeins-GUI Date: Fri, 7 Mar 2025 01:24:06 +0100 Subject: [PATCH 1/6] fix: fixed next hydration warning --- task2/src/app/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task2/src/app/layout.tsx b/task2/src/app/layout.tsx index fdb1dff..8d09992 100644 --- a/task2/src/app/layout.tsx +++ b/task2/src/app/layout.tsx @@ -18,7 +18,7 @@ export default function RootLayout({ children: React.ReactNode; }) { return ( - + Date: Fri, 7 Mar 2025 01:25:24 +0100 Subject: [PATCH 2/6] feat: generated metadata for every blog post for better seo --- task2/src/app/blog/[id]/page.tsx | 40 +++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/task2/src/app/blog/[id]/page.tsx b/task2/src/app/blog/[id]/page.tsx index a700aa8..2936a0f 100644 --- a/task2/src/app/blog/[id]/page.tsx +++ b/task2/src/app/blog/[id]/page.tsx @@ -3,13 +3,45 @@ import { CommentSection } from "@/components/CommentSection"; import { DeleteBlogButton } from "@/components/DeleteBlogButton"; import { supabase } from "@/lib/supabase"; import { Blog } from "@/supbase"; +import { capitalize } from "@/utils/string"; import { formatDistanceToNow } from "date-fns"; import { Calendar, Tag, User } from "lucide-react"; +import { Metadata } from "next"; import { getServerSession } from "next-auth/next"; import { notFound } from "next/navigation"; import ReactMarkdown from "react-markdown"; import "react-markdown-editor-lite/lib/index.css"; +type User = { + id: string; + email: string; + name: string; +}; + +type Props = { + params: Promise<{ id: string }>; +}; + +export async function generateMetadata({ params }: Props): Promise { + const { id } = await params; + + const { data: blog } = await supabase + .from("blogs") + .select("*") + .eq("id", id) + .single(); + + return { + title: blog?.title, + openGraph: { + description: blog?.excerpt, + publishedTime: `${new Date(`${blog?.created_at}`).getTime()}`, + tags: blog?.category, + writers: blog?.author, + }, + }; +} + export default async function BlogPost({ params, }: { @@ -23,6 +55,12 @@ export default async function BlogPost({ .single(); const session = await getServerSession(authOptions); + const { data: blogAuthor } = await supabase + .from("users") + .select("*") + .eq("id", blog?.author) + .single(); + if (!blog) { notFound(); } @@ -38,7 +76,7 @@ export default async function BlogPost({
- {blog.author} + {capitalize(blogAuthor?.name)} {formatDistanceToNow(blog.created_at)} ago From 2333b5c9f0fac66e4cb37d86ddbd29250c40b5af Mon Sep 17 00:00:00 2001 From: Oyeins-GUI Date: Fri, 7 Mar 2025 01:26:12 +0100 Subject: [PATCH 3/6] chore: updated link href --- task2/src/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task2/src/app/page.tsx b/task2/src/app/page.tsx index 725de20..6fa96de 100644 --- a/task2/src/app/page.tsx +++ b/task2/src/app/page.tsx @@ -34,7 +34,7 @@ export default function Home() {
From ac06ff2a8dffb39697a3036d4ed03fe535f9db16 Mon Sep 17 00:00:00 2001 From: Oyeins-GUI Date: Fri, 7 Mar 2025 01:26:57 +0100 Subject: [PATCH 4/6] added string capitalization utility func --- task2/src/utils/string.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 task2/src/utils/string.ts diff --git a/task2/src/utils/string.ts b/task2/src/utils/string.ts new file mode 100644 index 0000000..416ef11 --- /dev/null +++ b/task2/src/utils/string.ts @@ -0,0 +1,4 @@ +export function capitalize(text: string | undefined) { + if (!text) return ""; + return text.charAt(0).toUpperCase() + text.slice(1); +} From 3b26203a3010a3faf57284ad392910768136651a Mon Sep 17 00:00:00 2001 From: Oyeins-GUI Date: Fri, 7 Mar 2025 03:36:32 +0100 Subject: [PATCH 5/6] feat: redirect user to callback url after signin --- task2/src/app/auth/signin/page.tsx | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/task2/src/app/auth/signin/page.tsx b/task2/src/app/auth/signin/page.tsx index a3922db..6c74e00 100644 --- a/task2/src/app/auth/signin/page.tsx +++ b/task2/src/app/auth/signin/page.tsx @@ -2,14 +2,7 @@ import type React from "react"; -import { useEffect, useState } from "react"; -import { signIn } from "next-auth/react"; -import { useRouter } from "next/navigation"; -import { motion } from "framer-motion"; -import { Mail, Lock, Loader2 } from "lucide-react"; import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; import { Card, CardContent, @@ -17,20 +10,21 @@ import { CardHeader, CardTitle, } from "@/components/ui/card"; -import { useSession } from "next-auth/react"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; import { toast } from "@/components/ui/use-toast"; +import { motion } from "framer-motion"; +import { Loader2, Lock, Mail } from "lucide-react"; +import { signIn } from "next-auth/react"; +import { useRouter, useSearchParams } from "next/navigation"; +import { useState } from "react"; export default function SignIn() { + const searchParams = useSearchParams(); + const callbackUrl = searchParams.get("callbackUrl") ?? "/blog"; const router = useRouter(); const [error, setError] = useState(""); const [isLoading, setIsLoading] = useState(false); - const { data: session } = useSession(); - - useEffect(() => { - if (session) { - router.push("/blog"); - } - }, [session, router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -43,6 +37,7 @@ export default function SignIn() { email: formData.get("email"), password: formData.get("password"), redirect: false, + callbackUrl, }); if (response?.error) { @@ -50,7 +45,7 @@ export default function SignIn() { setError("Invalid credentials"); setIsLoading(false); } else { - router.push("/blog"); + router.push(callbackUrl); router.refresh(); } } catch (error) { From 9e88845e0a74cc3b221793b9ceb8f720a6f2d603 Mon Sep 17 00:00:00 2001 From: Oyeins-GUI Date: Fri, 7 Mar 2025 03:46:33 +0100 Subject: [PATCH 6/6] fix: add suspense boundary for useSearchParams as adviced by nextjs --- task2/src/app/auth/layout.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/task2/src/app/auth/layout.tsx b/task2/src/app/auth/layout.tsx index 2f11187..d98da4a 100644 --- a/task2/src/app/auth/layout.tsx +++ b/task2/src/app/auth/layout.tsx @@ -1,7 +1,13 @@ +import { Suspense } from "react"; + export default function AuthLayout({ children, }: { children: React.ReactNode; }) { - return
{children}
; + return ( +
+ {children} +
+ ); }