= async (values) => {
- setIsLoading(true);
- try {
- if (!session) {
- return router.push("/signin");
- }
- const response = await fetch("/api/user", {
- method: "POST",
- body: JSON.stringify({ ...values, session }),
- });
- setIsLoading(false);
- toast.success("Your Blog has been posted");
- reset();
- router.push("/blogs");
- } catch (error) {
- toast.error("Something went wrong");
- } finally {
- setIsLoading(false);
- }
- };
-
- return (
-
- );
-}
diff --git a/app/protected/[user]/page.tsx b/app/protected/[user]/page.tsx
index dd95785..2f28d6c 100644
--- a/app/protected/[user]/page.tsx
+++ b/app/protected/[user]/page.tsx
@@ -4,11 +4,11 @@ import { useSession } from "next-auth/react";
import { useState, useEffect } from "react";
import { useParams } from "next/navigation";
import { Card, CardBody, CardHeader, CardFooter, Button, useDisclosure } from "@nextui-org/react";
-import { Blog } from "@/models/UserModel";
import { FaEdit } from "react-icons/fa";
import Link from "next/link";
import Image from "next/image";
+import { Blog } from "@/models/UserModel";
import Loader from "@/components/Loader";
import PostModal from "@/components/PostModal";
import firstBlog from "@/assets/dazzle-blog-post-article.gif";
@@ -46,14 +46,13 @@ export default function User() {
) : blogs.length !== 0 ? (
-
- Your Blogs
+
{blogs.map((blog: Blog) => (
-
-
+
{blog.title}
{blog.content}
@@ -61,7 +60,7 @@ export default function User() {
as={Link}
color="primary"
href={`/protected/${params.user}/${blog._id}`}
- variant="flat"
+ className="font-semibold"
>
Edit
@@ -74,7 +73,6 @@ export default function User() {
) : (
- {/*
*/}
Write your first Post
diff --git a/components/BlogCard.tsx b/components/BlogCard.tsx
index 4e928ec..f89416b 100644
--- a/components/BlogCard.tsx
+++ b/components/BlogCard.tsx
@@ -1,11 +1,7 @@
-"use client";
-import { Blog } from "@/models/UserModel";
-
-import LikeButton from "./LikeButton";
-
-import React, { useEffect } from "react";
import { Card, CardBody, CardHeader, CardFooter } from "@nextui-org/card";
+import { Blog } from "@/models/UserModel";
+import LikeButton from "./LikeButton";
import CommentButton from "./CommentButton";
interface CardProps {
@@ -15,8 +11,6 @@ interface CardProps {
}
const BlogCard = ({ blog, handleLike, handleComment }: CardProps) => {
- console.log("rendered");
- console.log(blog);
return (
<>
diff --git a/utils/BaseUrl.ts b/utils/BaseUrl.ts
new file mode 100644
index 0000000..e69de29
diff --git a/utils/connectMongo.js b/utils/connectMongo.js
index ded3e04..3defd46 100644
--- a/utils/connectMongo.js
+++ b/utils/connectMongo.js
@@ -1,3 +1,3 @@
import mongoose from "mongoose";
-const connectMongo= async()=>(mongoose.connect('mongodb://127.0.0.1:27017/Users'))
-export default connectMongo
\ No newline at end of file
+const connectMongo = async () => mongoose.connect(process.env.MONGODB_URI);
+export default connectMongo;