From 9b6e62263dd16d7188771b918324072d48bf280e Mon Sep 17 00:00:00 2001 From: Victor Ejike Nwosu Date: Mon, 4 Nov 2024 15:01:00 +0100 Subject: [PATCH] Revert "Add better UI for different cases" This reverts commit 41437294af493eda1c6ebccc538e463fc2a0d35b. --- app/notes/[noteId]/page.tsx | 28 ++++++++-------------------- database/notes.ts | 16 ---------------- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/app/notes/[noteId]/page.tsx b/app/notes/[noteId]/page.tsx index de8cc0d..8cd7df1 100644 --- a/app/notes/[noteId]/page.tsx +++ b/app/notes/[noteId]/page.tsx @@ -1,6 +1,6 @@ import { cookies } from 'next/headers'; import Link from 'next/link'; -import { getNote, selectNoteExists } from '../../../database/notes'; +import { getNote } from '../../../database/notes'; type Props = { params: Promise<{ @@ -11,29 +11,18 @@ type Props = { export default async function NotePage(props: Props) { // Task: Restrict access to the note page only to the user who created the note - const noteId = Number((await props.params).noteId); - // 1. Checking if the sessionToken cookie exists const sessionTokenCookie = (await cookies()).get('sessionToken'); - // 2. Check if the note exists - const noteExists = await selectNoteExists(noteId); - - if (!noteExists) { - return ( -
-

Error loading note {noteId}

-
The note does not exist
- Back to notes -
- ); - } - - // 3. Query the note with the session token and noteId + // 2. Query the note with the session token and noteId const note = - sessionTokenCookie && (await getNote(sessionTokenCookie.value, noteId)); + sessionTokenCookie && + (await getNote( + sessionTokenCookie.value, + Number((await props.params).noteId), + )); - // 4. If there is no note for the current user, show restricted access message + // 3. If there is no note for the current user, show restricted access message if (!note) { return (
@@ -44,7 +33,6 @@ export default async function NotePage(props: Props) { ); } - // 5. Finally display the notes created by the current user return (

{note.title}

diff --git a/database/notes.ts b/database/notes.ts index 9a55f10..267f945 100644 --- a/database/notes.ts +++ b/database/notes.ts @@ -38,22 +38,6 @@ export const getNote = cache( }, ); -export async function selectNoteExists(noteId: Note['id']) { - const [record] = await sql<{ exists: boolean }[]>` - SELECT - EXISTS ( - SELECT - TRUE - FROM - notes - WHERE - id = ${noteId} - ) - `; - - return Boolean(record?.exists); -} - export const createNote = cache( async ( sessionToken: Session['token'],