From f76684cf8c83b52e62bc5aa676656511877ada28 Mon Sep 17 00:00:00 2001 From: shadcn Date: Mon, 7 Nov 2022 17:05:45 +0400 Subject: [PATCH] Revert "fix: remove redirect for now" This reverts commit 2980f245d3823f0887453991918e55eb095dcf93. --- app/(dashboard)/dashboard/page.tsx | 8 ++++++++ app/(dashboard)/dashboard/settings/page.tsx | 7 +++++++ app/(editor)/editor/[postId]/page.tsx | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/(dashboard)/dashboard/page.tsx b/app/(dashboard)/dashboard/page.tsx index fb1d4b0..db82e1a 100644 --- a/app/(dashboard)/dashboard/page.tsx +++ b/app/(dashboard)/dashboard/page.tsx @@ -1,6 +1,9 @@ +import { redirect } from "next/navigation" + import { db } from "@/lib/db" import { getCurrentUser } from "@/lib/session" import { User } from "@/lib/prisma" +import { authOptions } from "@/lib/auth" import { DashboardHeader } from "@/components/dashboard-header" import { PostCreateButton } from "@/components/post-create-button" import { DashboardShell } from "@/components/dashboard-shell" @@ -26,6 +29,11 @@ async function getPostsForUser(userId: User["id"]) { export default async function DashboardPage() { const user = await getCurrentUser() + + if (!user) { + redirect(authOptions.pages.signIn) + } + const posts = await getPostsForUser(user.id) return ( diff --git a/app/(dashboard)/dashboard/settings/page.tsx b/app/(dashboard)/dashboard/settings/page.tsx index 26a2bb3..7270556 100644 --- a/app/(dashboard)/dashboard/settings/page.tsx +++ b/app/(dashboard)/dashboard/settings/page.tsx @@ -1,4 +1,7 @@ +import { redirect } from "next/navigation" + import { getCurrentUser } from "@/lib/session" +import { authOptions } from "@/lib/auth" import { DashboardHeader } from "@/components/dashboard-header" import { DashboardShell } from "@/components/dashboard-shell" import { UserNameForm } from "@/components/user-name-form" @@ -6,6 +9,10 @@ import { UserNameForm } from "@/components/user-name-form" export default async function SettingsPage() { const user = await getCurrentUser() + if (!user) { + redirect(authOptions.pages.signIn) + } + return (