diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 18acd1f..fb2b3fd 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -1,3 +1,5 @@ +"use server"; + import { redirect } from "next/navigation"; import { cookies } from "next/headers"; import { usersTable } from "@/lib/db/schema"; @@ -87,20 +89,24 @@ export async function getAuth() { return null; } - const decodedToken = jwt.decode(token) as jwt.JwtPayload; - const username = decodedToken.sub; - if (!username) { + try { + const decodedToken = jwt.verify(token, JWT_SECRET) as jwt.JwtPayload; + const username = decodedToken.sub; + if (!username) { + return null; + } + + const users = await db.select() + .from(usersTable) + .where(eq(usersTable.username, username)); + if (users.length === 0) { + return null; + } + + return users[0]; + } catch { return null; } - - const users = await db.select() - .from(usersTable) - .where(eq(usersTable.username, username)); - if (users.length === 0) { - return null; - } - - return users[0]; } export async function logOut() { diff --git a/src/app/auth/page.tsx b/src/app/auth/page.tsx index 02f73e5..ab3766f 100644 --- a/src/app/auth/page.tsx +++ b/src/app/auth/page.tsx @@ -9,14 +9,12 @@ export const metadata: Metadata = { export default function About() { return ( <> -
-

Authenticate

-
- - -
+

Authenticate

+
+ +
-
+

Welcome to Rhyme!

Free service for writing and saving notes, lyrics, poetry, etc

Made with ❤️ by Kirill Siukhin

diff --git a/src/app/page.tsx b/src/app/page.tsx index 0be1497..d937aca 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -14,7 +14,7 @@ export default async function Home() { Changes are not saved!
- Log in to save your notes. + Log in to save your notes.
); diff --git a/src/components/editor/Block.tsx b/src/components/editor/Block.tsx index bf5bd8c..0b1a166 100644 --- a/src/components/editor/Block.tsx +++ b/src/components/editor/Block.tsx @@ -1,10 +1,9 @@ -"use client"; - -import { ArrowDown, ArrowUp, LockOpen, Minus, Plus, X } from "lucide-react"; +import { ArrowDown, ArrowUp, LockOpen, Lock, Minus, Plus, X } from "lucide-react"; +import { IBlock } from "@/lib/db/schema"; import IconOnlyButton from "../ui/IconOnlyButton"; import LineInput from "./LineInput"; -export default function Block() { +export default function Block({ block }: { block: IBlock }) { return (
@@ -12,8 +11,9 @@ export default function Block() { type="text" placeholder="enter tag..." className="w-full focus:outline-none" + defaultValue={block.tag} /> - + {block.lines.map((line, i) => )}
} /> @@ -25,7 +25,10 @@ export default function Block() {
} /> - } /> + : } + />
diff --git a/src/components/editor/Editor.tsx b/src/components/editor/Editor.tsx index 1f90bc8..d8f53c6 100644 --- a/src/components/editor/Editor.tsx +++ b/src/components/editor/Editor.tsx @@ -1,14 +1,41 @@ -"use client"; - import { Copy, Plus } from "lucide-react"; +import { v4 as uuidv4 } from "uuid"; +import { IBlock, INote } from "@/lib/db/schema"; import IconOnlyButton from "../ui/IconOnlyButton"; import Block from "./Block"; -export default function Editor() { +const defaultNoteId = uuidv4(); + +const defaultNote: INote = { + id: defaultNoteId, + title: "Untitled", + creationTime: new Date(), + lastEdited: new Date(), + authorId: uuidv4(), +}; + +const defaultBlocks: IBlock[] = [ + { + id: uuidv4(), + tag: "", + lines: ["", "", "", ""], + isLocked: false, + order: 1, + noteId: defaultNoteId, + }, +]; + +export default function Editor({ + note = defaultNote, + blocks = defaultBlocks, +}: { + note?: INote; + blocks?: IBlock[]; +}) { return (
- - + + {blocks.map((block) => )}
} /> } title="Copy note to clipboard" />