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 ( <> -
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() {