From 8931f21ada7591c7fad8b018cc77ffb64899ebd3 Mon Sep 17 00:00:00 2001 From: Wesley Souza | Neo Date: Wed, 6 Nov 2024 09:16:29 -0300 Subject: [PATCH] feat: :sparkles: add a function to redirect if user is not logged yet to login page --- app/page.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 3274491..499de4a 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,9 +1,18 @@ -const Home = () => { - return ( +import { auth } from "@clerk/nextjs/server"; +import { redirect } from "next/navigation"; + +const Home = async () => { + const { userId } = await auth(); + + if (!userId) { + redirect("/login"); + } + + return (

Home

); -} - -export default Home; \ No newline at end of file +}; + +export default Home;