From 689176b38e71d09b5bde3d10ce9a65892e7401b0 Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Sun, 26 May 2024 20:28:12 +0800 Subject: [PATCH 01/16] default --- .vscode/settings.json | 2 ++ next.config.mjs | 5 ++++- package-lock.json | 1 + src/_middleware.ts | 2 +- src/auth.ts | 9 ++++++++- 5 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/next.config.mjs b/next.config.mjs index 8fdfaf2..a0de28c 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,9 +1,12 @@ /** @type {import('next').NextConfig} */ const nextConfig = { images: { + domains: ["avatars.githubusercontent.com"], remotePatterns: [ { - hostname: "lh3.googleusercontent.com", + hostname: "lh3.googleusercontent.com", + //it is better not to include it here. it has payment. + //it is better if you will let user upload their profile pictures }, ], }, diff --git a/package-lock.json b/package-lock.json index cdc5187..64e12fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "next-auth-v5-steps", "version": "0.1.0", + "hasInstallScript": true, "dependencies": { "@auth/prisma-adapter": "^1.6.0", "@hookform/resolvers": "^3.3.4", diff --git a/src/_middleware.ts b/src/_middleware.ts index 8155fe0..4c07294 100644 --- a/src/_middleware.ts +++ b/src/_middleware.ts @@ -1 +1 @@ -export { auth as middleware } from "@/auth"; +export { auth as middleware } from "@/auth"; \ No newline at end of file diff --git a/src/auth.ts b/src/auth.ts index 6230950..44244af 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,11 +1,12 @@ -import { PrismaAdapter } from "@auth/prisma-adapter"; import NextAuth from "next-auth"; +import { PrismaAdapter } from "@auth/prisma-adapter"; import { Adapter } from "next-auth/adapters"; import GitHub from "next-auth/providers/github"; import Google from "next-auth/providers/google"; import Resend from "next-auth/providers/resend"; import prisma from "./lib/prisma"; + export const { handlers, signIn, signOut, auth } = NextAuth({ trustHost: true, theme: { @@ -26,3 +27,9 @@ export const { handlers, signIn, signOut, auth } = NextAuth({ }), ], }); + +// export const { handlers, signIn, signOut, auth } = NextAuth({ +// adapter: PrismaAdapter(prisma) as Adapter, +// providers: [], +// }); + From 5069e5e2bd4697075ecdf785f1b7c5fba06a3482 Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Sun, 26 May 2024 20:48:24 +0800 Subject: [PATCH 02/16] Updated --- prisma/schema.prisma | 1 - 1 file changed, 1 deletion(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 63f19a0..35f8cd9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -3,7 +3,6 @@ // Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? // Try Prisma Accelerate: https://pris.ly/cli/accelerate-init - generator client { provider = "prisma-client-js" previewFeatures = ["driverAdapters"] From 0e8a61437f9aab60cfc8939f908aa3db565c57cc Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Sun, 26 May 2024 20:55:42 +0800 Subject: [PATCH 03/16] Nice --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index da2b764..c49221a 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,6 @@ Topics I cover: - Static caching - And more +- Something + ![thumbnail](https://github.com/codinginflow/next-auth-v5/assets/52977034/99f6ae1c-b58e-46f2-adc6-fcc5ceeadaf2) From e8f3692b12f37a8588b359537fd4a2a5c7c892ce Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Sun, 26 May 2024 21:04:12 +0800 Subject: [PATCH 04/16] remove resend --- src/auth.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index 44244af..577b315 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -22,9 +22,9 @@ export const { handlers, signIn, signOut, auth } = NextAuth({ providers: [ Google, GitHub, - Resend({ - from: "no-reply@tutorial.codinginflow.com", - }), + // Resend({ + // from: "no-reply@tutorial.codinginflow.com", + // }), ], }); From 7ee8d7b9a3035fdbef0a6336ce5d4102730a3d0a Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Sun, 26 May 2024 21:08:25 +0800 Subject: [PATCH 05/16] Preparing to customize --- src/app/user/[id]/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/user/[id]/page.tsx b/src/app/user/[id]/page.tsx index aa26f5e..ed69b04 100644 --- a/src/app/user/[id]/page.tsx +++ b/src/app/user/[id]/page.tsx @@ -51,7 +51,7 @@ export default async function Page({ params: { id } }: PageProps) { {user?.name || `User ${id}`}

- User since {new Date(user.createdAt).toLocaleDateString()} + User since: {new Date(user.createdAt).toLocaleDateString()}

); From fd44ed29b8656ef2e4f400234f0c71dabf478b4b Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Fri, 31 May 2024 18:25:19 +0800 Subject: [PATCH 06/16] post model --- prisma/schema.prisma | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 35f8cd9..e959fa0 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -23,6 +23,7 @@ model User { role String? accounts Account[] sessions Session[] + posts Post[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@ -30,6 +31,19 @@ model User { @@map("users") } +model Post { + postId String @id @default(cuid()) + title String? + details String? + + user User @relation(fields: [postId], references: [id], onDelete: Cascade) + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt + + @@map("posts") +} + model Account { userId String type String From e156f71d4b0059aa76d2a06bcbf485824dc3b46b Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Fri, 31 May 2024 19:44:32 +0800 Subject: [PATCH 07/16] contributor --- prisma/schema.prisma | 3 +- src/app/contributor/create/CreatePostPage.tsx | 89 +++++++++++++++++++ src/app/contributor/create/actions.ts | 29 ++++++ src/app/contributor/create/page.tsx | 20 +++++ src/app/contributor/page.tsx | 31 +++++++ src/app/page.tsx | 18 ++-- src/components/NavBar.tsx | 2 +- src/components/UserButton.tsx | 12 ++- src/lib/validation.ts | 8 ++ 9 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 src/app/contributor/create/CreatePostPage.tsx create mode 100644 src/app/contributor/create/actions.ts create mode 100644 src/app/contributor/create/page.tsx create mode 100644 src/app/contributor/page.tsx diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e959fa0..efbe84f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -36,7 +36,8 @@ model Post { title String? details String? - user User @relation(fields: [postId], references: [id], onDelete: Cascade) + userId String + user User @relation(fields: [userId], references: [id], onDelete: Cascade) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/src/app/contributor/create/CreatePostPage.tsx b/src/app/contributor/create/CreatePostPage.tsx new file mode 100644 index 0000000..d18b17f --- /dev/null +++ b/src/app/contributor/create/CreatePostPage.tsx @@ -0,0 +1,89 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { useToast } from "@/components/ui/use-toast"; +import { CreatePostValues, createPostSchema } from "@/lib/validation"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useSession } from "next-auth/react"; +import { useForm } from "react-hook-form"; +import { createPost } from "./actions"; + +export default function CreatePostPage() { + const { toast } = useToast(); + const session = useSession(); + + const form = useForm({ + resolver: zodResolver(createPostSchema), + defaultValues: { + title: '', // Initialize to an empty string + details: '', // Initialize to an empty string + }, + }); + + + async function onSubmit(data: CreatePostValues) { + try { + await createPost(data); + toast({ description: "Post created." }); + } catch (error) { + toast({ + variant: "destructive", + description: "An error occurred. Please try again.", + }); + } + } + + return ( +
+
+

Create Post

+
+ + ( + + Title + + + + + + )} + /> + ( + + Details + + + + + + */} +
+
+
+

+ Michael GoughMichael Gough

+

Feb. 8, 2022

+
+ + {/* Dropdown menu */} + +
+

Very straight-to-point article. Really worth time reading. Thank you! But tools are just the + instruments for the UX designers. The knowledge of the design tools are as important as the + creation of the design strategy.

+
+ +
+
+
+
+
+

Jese LeosJese Leos

+

Feb. 12, 2022

+
+ + {/* Dropdown menu */} + +
+

Much appreciated! Glad you liked it ☺️

+
+ +
+
+
+
+
+

Bonnie GreenBonnie Green

+

Mar. 12, 2022

+
+ + {/* Dropdown menu */} + +
+

The article covers the essentials, challenges, myths and stages the UX designer should consider while creating the design strategy.

+
+ +
+
+
+
+
+

Helene EngelsHelene Engels

+

Jun. 23, 2022

+
+ + {/* Dropdown menu */} + +
+

Thanks for sharing this. I do came from the Backend development and explored some of the tools to design my Side Projects.

+
+ +
+
+
+ + +
+ +{/* */} + +
+
+
+

Sign up for our newsletter

+

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

+
+
+
+ +
+ +
+ +
+
+ +
+
+
We care about the protection of your data. Read our Privacy Policy.
+
+
+
+
+ + + + + ); +} diff --git a/src/app/user/[id]/page.tsx b/src/app/user/[id]/page.tsx index ed69b04..7fbf03a 100644 --- a/src/app/user/[id]/page.tsx +++ b/src/app/user/[id]/page.tsx @@ -1,46 +1,55 @@ +// Import the Prisma client for database operations import prisma from "@/lib/prisma"; +// Import the Image component from Next.js for optimized images import Image from "next/image"; +// Import the notFound function to handle 404 errors import { notFound } from "next/navigation"; +// Import the cache function from React to cache data import { cache } from "react"; +// Define the shape of the page's props interface PageProps { - params: { id: string }; + params: { id: string }; // Page parameters include a user ID } +// Function to get user data, caching the result for performance const getUser = cache(async (id: string) => { return prisma.user.findUnique({ - where: { id }, - select: { id: true, name: true, image: true, createdAt: true }, + where: { id }, // Find user by ID + select: { id: true, name: true, image: true, createdAt: true }, // Select specific fields }); }); +// Function to generate static parameters for dynamic routes export async function generateStaticParams() { - const allUsers = await prisma.user.findMany(); + const allUsers = await prisma.user.findMany(); // Get all users from the database - return allUsers.map(({ id }) => ({ id })); + return allUsers.map(({ id }) => ({ id })); // Return an array of user IDs } +// Function to generate metadata for each page export async function generateMetadata({ params: { id } }: PageProps) { - const user = await getUser(id); + const user = await getUser(id); // Get user data by ID return { - title: user?.name || `User ${id}`, + title: user?.name || `User ${id}`, // Set the page title to the user's name or default to "User [ID]" }; } +// Main page component export default async function Page({ params: { id } }: PageProps) { - // Artificial delay to showcase static caching + // Artificial delay to simulate loading time await new Promise((resolve) => setTimeout(resolve, 1500)); - const user = await getUser(id); + const user = await getUser(id); // Get user data by ID - if (!user) notFound(); + if (!user) notFound(); // If no user is found, show a 404 error return (
{user.image && ( User profile picture )}

- {user?.name || `User ${id}`} + {/* Display user's name or default to "User [ID]" */} + {user?.name || `User ${id}`}

- User since: {new Date(user.createdAt).toLocaleDateString()} + {/* Display the date when the user joined */} + User since: {new Date(user.createdAt).toLocaleDateString()}

); diff --git a/tailwind.config.js b/tailwind.config.js index d8b4566..1573f13 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -11,5 +11,7 @@ module.exports = { theme: { extend: {}, }, - plugins: [], + plugins: [ + require("flowbite-typography"), + ], }; From 362d781da5a4c0fed18bd628924c99129ef49993 Mon Sep 17 00:00:00 2001 From: Joseph Cutor Date: Sat, 1 Jun 2024 21:46:31 +0800 Subject: [PATCH 11/16] tina-try confirm --- src/components/NavBar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index f9e1517..9165415 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -13,7 +13,7 @@ export default function NavBar() {