diff --git a/src/app/api/blogs/[id]/route.ts b/src/app/api/blogs/[id]/route.ts new file mode 100644 index 0000000..7b9a0d2 --- /dev/null +++ b/src/app/api/blogs/[id]/route.ts @@ -0,0 +1,27 @@ +/*import { NextRequest, NextResponse } from "next/server"; +import { auth } from "@/lib/auth"; + +export async function DELETE( + request: NextRequest, + { params }: { params: Promise<{ id: string }> } +) { + try { + const session = await auth(); + + if (!session?.user?.id) { + return NextResponse.json( + { error: "Unauthorized" }, + { status: 401 } + ); + } + + const { id } = await params; + + return NextResponse.json({ success: true }); + } catch (error) { + return NextResponse.json( + { error: error instanceof Error ? error.message : "Failed to delete blog" }, + { status: 400 } + ); + } +}*/ diff --git a/src/app/api/blogs/route.ts b/src/app/api/blogs/route.ts index 549c388..9baa46d 100644 --- a/src/app/api/blogs/route.ts +++ b/src/app/api/blogs/route.ts @@ -1,14 +1,39 @@ import { NextResponse } from "next/server"; import { CreateBlogSchema } from "@/schemas/CreateBlogSchema"; import { createBlogs, getBlogs } from "@/actions/blogs"; +import { auth } from "@/lib/auth"; export async function POST(request: Request) { try { + // Check authentication + const session = await auth(); + + if (!session?.user?.id) { + return NextResponse.json( + { error: "Unauthorized. Please log in to create blogs." }, + { status: 401 }, + ); + } + const body = await request.json(); // Validate request body const validatedData = CreateBlogSchema.parse(body); + // Validate that all blogs have the authenticated user as author + for (const blog of validatedData) { + if (blog.authorId !== session.user.id) { + return NextResponse.json( + { + error: "Forbidden. You can only create blogs as yourself.", + providedAuthorId: blog.authorId, + authenticatedUserId: session.user.id + }, + { status: 403 }, + ); + } + } + // Create the blogs const blogs = await createBlogs(validatedData); diff --git a/src/app/api/paper/[id]/route.ts b/src/app/api/paper/[id]/route.ts new file mode 100644 index 0000000..6043d38 --- /dev/null +++ b/src/app/api/paper/[id]/route.ts @@ -0,0 +1,27 @@ +/*import { NextRequest, NextResponse } from "next/server"; +import { auth } from "@/lib/auth"; + +export async function DELETE( + request: NextRequest, + { params }: { params: Promise<{ id: string }> } +) { + try { + const session = await auth(); + + if (!session?.user?.id) { + return NextResponse.json( + { error: "Unauthorized" }, + { status: 401 } + ); + } + + const { id } = await params; + + return NextResponse.json({ success: true }); + } catch (error) { + return NextResponse.json( + { error: error instanceof Error ? error.message : "Failed to delete research paper" }, + { status: 400 } + ); + } +}*/ diff --git a/src/app/api/paper/route.ts b/src/app/api/paper/route.ts index 623a3fe..b176a76 100644 --- a/src/app/api/paper/route.ts +++ b/src/app/api/paper/route.ts @@ -1,14 +1,39 @@ import { NextRequest, NextResponse } from "next/server"; import { CreatePaperSchema } from "@/schemas/CreatePaperSchema"; import { createPapers, fetchPapers } from "@/actions/papers"; +import { auth } from "@/lib/auth"; export async function POST(request: NextRequest) { try { + // Check authentication + const session = await auth(); + + if (!session?.user?.id) { + return NextResponse.json( + { error: "Unauthorized. Please log in to create research papers." }, + { status: 401 }, + ); + } + const body = await request.json(); // Validate request body const validatedData = CreatePaperSchema.parse(body); + // Validate that authenticated user is included as an author in all papers + for (const paper of validatedData) { + if (!paper.authorIds.includes(session.user.id)) { + return NextResponse.json( + { + error: "Forbidden. You must include yourself as an author.", + providedAuthorIds: paper.authorIds, + authenticatedUserId: session.user.id + }, + { status: 403 }, + ); + } + } + // Create the paper const paper = await createPapers(validatedData); diff --git a/src/app/u/[id]/edit/page.tsx b/src/app/u/[id]/edit/page.tsx index c03211e..ffd172f 100644 --- a/src/app/u/[id]/edit/page.tsx +++ b/src/app/u/[id]/edit/page.tsx @@ -59,7 +59,7 @@ const EditProfilePage = async ({ params }: PageProps) => { Edit Profile
- Update your profile information and social links + Update your profile, information, social links, publish blogs, and add research papers
diff --git a/src/components/EditProfileForm.tsx b/src/components/EditProfileForm.tsx index 18821db..cd09de5 100644 --- a/src/components/EditProfileForm.tsx +++ b/src/components/EditProfileForm.tsx @@ -7,9 +7,11 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { ImageUpload } from "@/components/ImageUpload"; +import { Badge } from "@/components/ui/badge"; import { updateUserProfile } from "@/actions/profile"; -import { Loader2, Save, X } from "lucide-react"; +import { Loader2, Save, X, Plus, User, BookOpen, FileText } from "lucide-react"; import { toast } from "sonner"; +import Image from "next/image"; interface EditProfileFormProps { user: { @@ -28,6 +30,9 @@ interface EditProfileFormProps { export function EditProfileForm({ user }: EditProfileFormProps) { const router = useRouter(); + const [activeSection, setActiveSection] = useState<"profile" | "blog" | "paper">("profile"); + + // Profile states const [name, setName] = useState(user.name || ""); const [imageUrl, setImageUrl] = useState(user.image || ""); const [designation, setDesignation] = useState(user.designation || ""); @@ -38,6 +43,28 @@ export function EditProfileForm({ user }: EditProfileFormProps) { const [github, setGithub] = useState(user.github || ""); const [isLoading, setIsLoading] = useState(false); + // Blog states + const [blogTitle, setBlogTitle] = useState(""); + //const [blogSlug, setBlogSlug] = useState(""); + //const [blogTldr, setBlogTldr] = useState(""); + const [blogContent, setBlogContent] = useState(""); + const [blogReadTime, setBlogReadTime] = useState(5); + const [blogPoster, setBlogPoster] = useState(""); + const [blogBanner, setBlogBanner] = useState(""); + const [blogTags, setBlogTags] = useState