From 3c4a999ef7beae85da50f3d9d1207426814be489 Mon Sep 17 00:00:00 2001 From: andrzej Date: Mon, 30 Sep 2024 16:06:52 +0200 Subject: [PATCH] tidy up --- prisma/dev.db | Bin 69632 -> 69632 bytes prisma/script.js | 39 ++++++++++++++----------------- src/app/api/auth/login/route.ts | 1 - src/app/lib/create.ts | 6 +---- src/app/login/page.tsx | 2 +- src/app/ui/tables/data-table.tsx | 2 +- 6 files changed, 21 insertions(+), 29 deletions(-) diff --git a/prisma/dev.db b/prisma/dev.db index 40fb7b9e717c3a818a1a6ee501b48feb00f06caf..cc2fe91e50fba46479a55c856cb21c2f0c054146 100644 GIT binary patch delta 268 zcmZozz|ydQWr8%L<3t%}M#qf_8U9kbJeH3{0NbT$-w`U|1Z_5wYk{%uQ2d`;(yG4 zXR^Qo$<68umhrQ50Hp)jSvFr;Z=e7)<1PdLZ~m|R@A+Q>mEGl^w^{7ML4G!7Mn>5n z{>^vqs{_^W<}mPY=2zjH%ICqmlQ)OQYO5F{C-3x$T#QcK3=B;385tXS85lLT=kPL4 GVFCczC`|AG diff --git a/prisma/script.js b/prisma/script.js index 65dac19..f8a8d21 100644 --- a/prisma/script.js +++ b/prisma/script.js @@ -1,27 +1,24 @@ -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from "@prisma/client"; -const prisma = new PrismaClient() +const prisma = new PrismaClient(); async function main() { - // ... you will write your Prisma Client queries here - const story = await prisma.story.update({ - where: { id: 1 }, - data: { - title: "Ghost Aliens of Mars", - genres: { set: [{ id: 1 }, { id: 2 }], create: { name: "alien-punk" } } - } - - }) - console.log(story) - + // ... you will write your Prisma Client queries here + const story = await prisma.story.update({ + where: { id: 1 }, + data: { + title: "Ghost Aliens of Mars", + genres: { set: [{ id: 1 }, { id: 2 }], create: { name: "alien-punk" } }, + }, + }); } main() - .then(async () => { - await prisma.$disconnect() - }) - .catch(async (e) => { - console.error(e) - await prisma.$disconnect() - process.exit(1) - }) + .then(async () => { + await prisma.$disconnect(); + }) + .catch(async (e) => { + console.error(e); + await prisma.$disconnect(); + process.exit(1); + }); diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index aa46161..6f439eb 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -15,7 +15,6 @@ const dynamic = 'force-dynamic' //POST endpoint export async function POST(request: NextRequest) { const body = await request.json() - console.log(`body: ${JSON.stringify(body)}`) const { email, password } = body if (!email || !password) { diff --git a/src/app/lib/create.ts b/src/app/lib/create.ts index 022b882..fd03fab 100644 --- a/src/app/lib/create.ts +++ b/src/app/lib/create.ts @@ -1,16 +1,12 @@ "use server" -import { Genre, Pub, Story, Sub } from "@prisma/client" +import { Pub, Story, Sub } from "@prisma/client" import prisma from "./db" import { revalidatePath } from "next/cache" -import { redirect } from "next/navigation" import { z } from "zod" -import { storySchema } from "app/ui/forms/schemas" import { pubSchema } from "app/ui/forms/schemas" import { subSchema } from "app/ui/forms/schemas" import { prepGenreData, prepStoryData } from "./validate" -import { SubForm } from "app/ui/forms/sub" -//TODO - data validation, error handling, unauthorized access handling export async function createStory({ story, genres }: { story: Story, genres: number[] }): Promise<{ success: string }> { // will return undefined if middleware authorization fails diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 188850f..42655b7 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -18,7 +18,6 @@ export default function LoginForm() { const router = useRouter() const searchParams = useSearchParams() const redirect = searchParams.get("from") ?? "/submission" - console.log(redirect) const form = useForm>({ resolver: zodResolver(loginSchema), }) @@ -37,6 +36,7 @@ export default function LoginForm() { toast({ title: "login successful!" }) setSubmitted(true) await revalidate(redirect) + //BUG:the first time user logs in, page refreshes instead of redirecting router.push(redirect) } else { toast({ title: "login failed!" }) diff --git a/src/app/ui/tables/data-table.tsx b/src/app/ui/tables/data-table.tsx index d31944a..913e689 100644 --- a/src/app/ui/tables/data-table.tsx +++ b/src/app/ui/tables/data-table.tsx @@ -136,7 +136,7 @@ export function DataTable({
-