Revert "fix: remove redirect for now"

This reverts commit 2980f245d3.
This commit is contained in:
shadcn 2022-11-07 17:05:45 +04:00
parent 2a037e5b0e
commit f76684cf8c
3 changed files with 22 additions and 1 deletions

View file

@ -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 (

View file

@ -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 (
<DashboardShell>
<DashboardHeader

View file

@ -1,8 +1,9 @@
import { notFound } from "next/navigation"
import { notFound, redirect } from "next/navigation"
import { Post, User } from "@/lib/prisma"
import { db } from "@/lib/db"
import { getCurrentUser } from "@/lib/session"
import { authOptions } from "@/lib/auth"
import { Editor } from "@/components/editor"
async function getPostForUser(postId: Post["id"], userId: User["id"]) {
@ -20,6 +21,11 @@ interface EditorPageProps {
export default async function EditorPage({ params }: EditorPageProps) {
const user = await getCurrentUser()
if (!user) {
redirect(authOptions.pages.signIn)
}
const post = await getPostForUser(params.postId, user.id)
if (!post) {