commit 17e26fc87fe742d5f3df2447fefa9fad2d1e066c Author: jamesratcliffe101 Date: Fri Apr 3 18:25:54 2026 +0100 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e215bc4 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). + +## Getting Started + +First, run the development server: + +```bash +npm run dev +# or +yarn dev +# or +pnpm dev +# or +bun dev +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. + +This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. + +## Learn More + +To learn more about Next.js, take a look at the following resources: + +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. + +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! + +## Deploy on Vercel + +The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. diff --git a/app/api/uploadthing/core.ts b/app/api/uploadthing/core.ts new file mode 100644 index 0000000..00d5383 --- /dev/null +++ b/app/api/uploadthing/core.ts @@ -0,0 +1,41 @@ +import { clerkClient, auth } from "@clerk/nextjs/server"; +import { createUploadthing, type FileRouter } from "uploadthing/next"; +import { UploadThingError } from "uploadthing/server"; +const f = createUploadthing(); + +// FileRouter for your app, can contain multiple FileRoutes +export const ourFileRouter = { + // Define as many FileRoutes as you like, each with a unique routeSlug + imageUploader: f({ + image: { + /** + * For full list of options and defaults, see the File Route API reference + * @see https://docs.uploadthing.com/file-routes#route-config + */ + maxFileSize: "4MB", + maxFileCount: 1, + }, + }) + // Set permissions and file types for this FileRoute + .middleware(async () => { + // This code runs on your server before upload + const user = await auth(); + + // If you throw, the user will not be able to upload + if (!user) throw new UploadThingError("Unauthorized"); + + // Whatever is returned here is accessible in onUploadComplete as `metadata` + return { userId: user.userId }; + }) + .onUploadComplete(async ({ metadata, file }) => { + // This code RUNS ON YOUR SERVER after upload + console.log("Upload complete for userId:", metadata.userId); + + console.log("file url", file.ufsUrl); + + // !!! Whatever is returned here is sent to the clientside `onClientUploadComplete` callback + return { uploadedBy: metadata.userId }; + }), +} satisfies FileRouter; + +export type OurFileRouter = typeof ourFileRouter; diff --git a/app/api/uploadthing/route.ts b/app/api/uploadthing/route.ts new file mode 100644 index 0000000..f659c0e --- /dev/null +++ b/app/api/uploadthing/route.ts @@ -0,0 +1,11 @@ +import { createRouteHandler } from "uploadthing/next"; + +import { ourFileRouter } from "./core"; + +// Export routes for Next App Router +export const { GET, POST } = createRouteHandler({ + router: ourFileRouter, + + // Apply an (optional) custom config: + // config: { ... }, +}); \ No newline at end of file diff --git a/app/create_post/layout.tsx b/app/create_post/layout.tsx new file mode 100644 index 0000000..ba7fcbc --- /dev/null +++ b/app/create_post/layout.tsx @@ -0,0 +1,5 @@ +export default function layout({ children }: { children: React.ReactNode}){ + return <> + {children} + +} \ No newline at end of file diff --git a/app/create_post/page.tsx b/app/create_post/page.tsx new file mode 100644 index 0000000..e7e3f02 --- /dev/null +++ b/app/create_post/page.tsx @@ -0,0 +1,57 @@ +import Form from 'next/form' +import { auth } from '@clerk/nextjs/server'; +import { prisma } from "@/lib/prisma"; +import { revalidatePath } from "next/cache"; +import { redirect } from "next/navigation"; + +export default async function Page() { + async function createPost(formData: FormData) { + "use server"; + + const { userId } = await auth(); // + if (!userId) { + throw new Error("You must be logged in to post!"); + } + + const first_name = formData.get("fname") as string; + const last_name = formData.get("lname") as string; + const post_text = formData.get("post-text") as string; + const pet_species = formData.get("pet_species") as string; + + console.log(first_name, last_name, post_text, pet_species); + + await prisma.post.create({ + data: { + content: post_text, + petId: 3, + }, + }); + + revalidatePath("/"); + redirect("/"); + } + + return <> +

This is create post content

+
+
+
+
+
+
+