diff --git a/apps/X/app/api/post/route.ts b/apps/X/app/api/post/route.ts
index 6549f4f..f29cb06 100644
--- a/apps/X/app/api/post/route.ts
+++ b/apps/X/app/api/post/route.ts
@@ -8,21 +8,35 @@ const prisma = new PrismaClient();
export async function GET() {
const session = await getServerSession(authOptions);
-
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
+ try {
+ const posts = await prisma.tweet.findMany({
+ include: {
+ user: {
+ select: {
+ name: true,
+ },
+ },
+ },
+ });
+ return NextResponse.json({ data: posts }, { status: 200 });
+ } catch (error) {
+ console.log("Error while fetching from DB", error);
+ }
+
return NextResponse.json({ userId: session.user.id });
}
export const POST = async (req: NextRequest) => {
try {
const session = await getServerSession(authOptions);
- console.log("Reaching in Post");
- console.log(session, "This is the user");
- console.log(session?.user.id, "This is the userID");
- console.log(session?.user, "This is the userID");
+ // console.log("Reaching in Post");
+ // console.log(session, "This is the user");
+ // console.log(session?.user.id, "This is the userID");
+ // console.log(session?.user, "This is the userID");
if (!session?.user?.id) {
return NextResponse.json(
diff --git a/apps/X/app/lib/auth.ts b/apps/X/app/lib/auth.ts
index 017188a..aee4889 100644
--- a/apps/X/app/lib/auth.ts
+++ b/apps/X/app/lib/auth.ts
@@ -5,7 +5,7 @@ import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
import { Session } from "next-auth";
import z from "zod";
-
+import type { Account, Profile, User } from "next-auth";
declare module "next-auth" {
interface Session {
user: {
@@ -115,7 +115,6 @@ export const authOptions = {
} else {
console.log("Invalid password for existing user");
}
- console.log("This is name", existingUser.name);
} catch (error) {
console.log("Error while LogIn", error);
}
@@ -151,9 +150,8 @@ export const authOptions = {
callbacks: {
async jwt({ token, user, account }: any) {
- console.log("JWT Callback - User:", user);
- console.log("JWT Callback - Account:", account);
- console.log("OOOOOOOOOOO", token.id);
+ //console.log("JWT Callback - User:", user);
+ //console.log("JWT Callback - Account:", account);
if (user) {
token.id = user.id;
@@ -163,8 +161,8 @@ export const authOptions = {
return token;
},
async session({ session, token }: any) {
- console.log("Session Callback - Token:", token);
- console.log("Session Callback - Initial Session:", session);
+ // console.log("Session Callback - Token:", token);
+ // console.log("Session Callback - Initial Session:", session);
if (token && session.user) {
session.user.id = token.id as string;
@@ -172,7 +170,7 @@ export const authOptions = {
session.user.email = token.email || null;
}
- console.log("Session Callback - Updated Session:", session);
+ //console.log("Session Callback - Updated Session:", session);
return session;
},
diff --git a/apps/X/src/components/ui/Post/TopPost.tsx b/apps/X/src/components/ui/Post/TopPost.tsx
index eb7fa5b..b5c9626 100644
--- a/apps/X/src/components/ui/Post/TopPost.tsx
+++ b/apps/X/src/components/ui/Post/TopPost.tsx
@@ -14,10 +14,10 @@ import { Button } from "../button";
import { Input } from "../input";
import { UserAvatar } from "../usrAvatar";
import X_Icon from "../X_Icon";
-interface TweetInput {
- content: string;
- userId: number;
-}
+// interface TweetInput {
+// content: string;
+// userId: number;
+// }
export const TopPost = () => {
const [postInput, setPostInput] = useState("");
diff --git a/apps/X/src/components/ui/TweetComp.tsx b/apps/X/src/components/ui/TweetComp.tsx
index 6cf5483..22f770d 100644
--- a/apps/X/src/components/ui/TweetComp.tsx
+++ b/apps/X/src/components/ui/TweetComp.tsx
@@ -1,72 +1,55 @@
-import { FaRegComment } from "react-icons/fa6";
+"use client";
import { BiRepost } from "react-icons/bi";
-import { UserAvatar } from "./usrAvatar";
+import { FaRegBookmark, FaRegComment } from "react-icons/fa6";
import { FiHeart } from "react-icons/fi";
import { IoIosStats } from "react-icons/io";
-import { FaRegBookmark } from "react-icons/fa6";
import { RiShare2Line } from "react-icons/ri";
-;
-export const TweetComp = () => {
- return (
-
-
-
-
-
-
-
-
-
username
-
@name
-
. time
-
-
...
-
-
-
- #day100 so finally I completed 100 day of code. Amazing journey
- amazing learning and amazing people I have got in this journey and
- here are some glimpse from the journey. Thank you everyone and
- specially @kirat_tw #100xdevs #buildinpublic #space
- #LearningJourney #WeekendPlans
-
-
Image Part
-
- {/*
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
*/}
+import { UserAvatar } from "./usrAvatar";
-
-
-
-
-
- {/*
-
-
-
-
+interface TweetProps {
+ tweet: {
+ id: number;
+ content: string;
+ userID: number;
+ likes: number;
+ createdDate: string;
+ user: { name: string };
+ };
+}
+
+export const TweetComp = ({ tweet }: TweetProps) => {
+ return (
+
+
+
+
+
+
-
*/}
-
-
-
+
+
+
{tweet.user.name}
+ {/*
@tweet.content
*/}
+
ยท {new Date(tweet.createdDate).toLocaleDateString()}
+
+
...
+
+
+
{tweet.content}
+
Image Part
+
+
+
+
+
+ {/*
{tweet.likes} */}
+
+
+
+
+
+
diff --git a/apps/X/src/components/ui/home/CenterComp.tsx b/apps/X/src/components/ui/home/CenterComp.tsx
index 8b70ccf..1ebb989 100644
--- a/apps/X/src/components/ui/home/CenterComp.tsx
+++ b/apps/X/src/components/ui/home/CenterComp.tsx
@@ -1,6 +1,43 @@
+"use client";
+import axios from "axios";
+import { useEffect, useState } from "react";
import { TopHead, TopPost, TweetComp } from "..";
+interface Tweet {
+ id: number;
+ content: string;
+ userID: number;
+ likes: number;
+ createdDate: string;
+ user: { name: string };
+}
export const CenterComp = () => {
+ const [tweets, setTweets] = useState
([]);
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState("");
+ const fetchTweets = async () => {
+ try {
+ setLoading(true);
+ const response = await axios.get("api/post");
+ const tweetData = response.data.data;
+ console.log(">>>>>>>>>>>>>>>>>>>>>>>>", tweetData);
+
+ if (Array.isArray(tweetData) && response.data.data.length > 0) {
+ setTweets(tweetData);
+ } else {
+ setError("No tweets found");
+ }
+ } catch (error) {
+ console.log("Getting error while fetching =>", error);
+ } finally {
+ setLoading(false);
+ }
+ const response = await axios.get("api/post");
+ console.log("This is from the Centercomp", response);
+ };
+ useEffect(() => {
+ fetchTweets();
+ }, []);
return (
@@ -9,13 +46,19 @@ export const CenterComp = () => {
-
-
-
-
-
-
-
+ {loading ? (
+
Loading
+ ) : error ? (
+
{error}
+ ) : (
+
+
+ {tweets.map((tweet) => (
+
+ ))}
+
+
+ )}
);
};
diff --git a/apps/X/src/components/ui/home/HomeComp.tsx b/apps/X/src/components/ui/home/HomeComp.tsx
index 1182bab..e29f502 100644
--- a/apps/X/src/components/ui/home/HomeComp.tsx
+++ b/apps/X/src/components/ui/home/HomeComp.tsx
@@ -2,22 +2,18 @@ import { CenterComp, HomeLeft, HomeRight } from "@/components/ui";
export const HomeComp = () => {
return (
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
- {/* border-slate-800 border border-y-0 h-screen */}
);
};
diff --git a/apps/X/src/components/ui/home/HomeLeft.tsx b/apps/X/src/components/ui/home/HomeLeft.tsx
index 6d96e9b..cdca2b4 100644
--- a/apps/X/src/components/ui/home/HomeLeft.tsx
+++ b/apps/X/src/components/ui/home/HomeLeft.tsx
@@ -130,7 +130,7 @@ export const HomeLeft = () => {
Post
diff --git a/package.json b/package.json
index 2f3dd63..0b1a58d 100644
--- a/package.json
+++ b/package.json
@@ -24,4 +24,4 @@
"@types/bcrypt": "^5.0.2",
"bcrypt": "^5.1.1"
}
-}
\ No newline at end of file
+}
diff --git a/yarn.lock b/yarn.lock
index 5893cc1..71955f9 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -509,22 +509,22 @@
"@prisma/client@^6.1.0":
version "6.1.0"
- resolved "https://registry.yarnpkg.com/@prisma/client/-/client-6.1.0.tgz#179d3b70586e7be522f6f1f0a82cca01396f719a"
+ resolved "https://registry.npmjs.org/@prisma/client/-/client-6.1.0.tgz"
integrity sha512-AbQYc5+EJKm1Ydfq3KxwcGiy7wIbm4/QbjCKWWoNROtvy7d6a3gmAGkKjK0iUCzh+rHV8xDhD5Cge8ke/kiy5Q==
"@prisma/debug@6.1.0":
version "6.1.0"
- resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-6.1.0.tgz#a27a1d144f72a3bc95061ecb0255e7554d9d59ec"
+ resolved "https://registry.npmjs.org/@prisma/debug/-/debug-6.1.0.tgz"
integrity sha512-0himsvcM4DGBTtvXkd2Tggv6sl2JyUYLzEGXXleFY+7Kp6rZeSS3hiTW9mwtUlXrwYbJP6pwlVNB7jYElrjWUg==
"@prisma/engines-version@6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959":
version "6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959"
- resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959.tgz#0b21ebf57362ffe35d0760c39855f90bbfa0f2fd"
+ resolved "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-6.1.0-21.11f085a2012c0f4778414c8db2651556ee0ef959.tgz"
integrity sha512-PdJqmYM2Fd8K0weOOtQThWylwjsDlTig+8Pcg47/jszMuLL9iLIaygC3cjWJLda69siRW4STlCTMSgOjZzvKPQ==
"@prisma/engines@6.1.0":
version "6.1.0"
- resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-6.1.0.tgz#2195244a8ce33839a8131e4465624e21d1f8d042"
+ resolved "https://registry.npmjs.org/@prisma/engines/-/engines-6.1.0.tgz"
integrity sha512-GnYJbCiep3Vyr1P/415ReYrgJUjP79fBNc1wCo7NP6Eia0CzL2Ot9vK7Infczv3oK7JLrCcawOSAxFxNFsAERQ==
dependencies:
"@prisma/debug" "6.1.0"
@@ -534,7 +534,7 @@
"@prisma/fetch-engine@6.1.0":
version "6.1.0"
- resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-6.1.0.tgz#2a5174787bf57c9b1d5d400bb923e0dc6a73a794"
+ resolved "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-6.1.0.tgz"
integrity sha512-asdFi7TvPlEZ8CzSZ/+Du5wZ27q6OJbRSXh+S8ISZguu+S9KtS/gP7NeXceZyb1Jv1SM1S5YfiCv+STDsG6rrg==
dependencies:
"@prisma/debug" "6.1.0"
@@ -543,7 +543,7 @@
"@prisma/get-platform@6.1.0":
version "6.1.0"
- resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-6.1.0.tgz#d4394a24ef91af6675a92382ed40e6e6e07eeb13"
+ resolved "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-6.1.0.tgz"
integrity sha512-ia8bNjboBoHkmKGGaWtqtlgQOhCi7+f85aOkPJKgNwWvYrT6l78KgojLekE8zMhVk0R9lWcifV0Pf8l3/15V0Q==
dependencies:
"@prisma/debug" "6.1.0"
@@ -555,7 +555,7 @@
"@radix-ui/react-avatar@^1.1.2":
version "1.1.2"
- resolved "https://registry.yarnpkg.com/@radix-ui/react-avatar/-/react-avatar-1.1.2.tgz#24af4c66bb5271460a4a6b74c4f4f9d4789d3d90"
+ resolved "https://registry.npmjs.org/@radix-ui/react-avatar/-/react-avatar-1.1.2.tgz"
integrity sha512-GaC7bXQZ5VgZvVvsJ5mu/AEbjYLnhhkoidOboC50Z6FFlLA03wG2ianUoH+zgDQ31/9gCF59bE4+2bBgTyMiig==
dependencies:
"@radix-ui/react-context" "1.1.1"
@@ -1157,7 +1157,7 @@ ast-types@^0.13.4:
asynckit@^0.4.0:
version "0.4.0"
- resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
+ resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz"
integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==
autoprefixer@^10.4.20:
@@ -1181,7 +1181,7 @@ available-typed-arrays@^1.0.7:
axios@^1.7.9:
version "1.7.9"
- resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.9.tgz#d7d071380c132a24accda1b2cfc1535b79ec650a"
+ resolved "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz"
integrity sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==
dependencies:
follow-redirects "^1.15.6"
@@ -1486,7 +1486,7 @@ color@^4.2.3:
combined-stream@^1.0.8:
version "1.0.8"
- resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
+ resolved "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
dependencies:
delayed-stream "~1.0.0"
@@ -1652,7 +1652,7 @@ del@^5.1.0:
delayed-stream@~1.0.0:
version "1.0.0"
- resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
+ resolved "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==
delegates@^1.0.0:
@@ -2167,7 +2167,7 @@ flatted@^3.2.9:
follow-redirects@^1.15.6:
version "1.15.9"
- resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
+ resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
for-each@^0.3.3:
@@ -2187,7 +2187,7 @@ foreground-child@^3.1.0:
form-data@^4.0.0:
version "4.0.1"
- resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.1.tgz#ba1076daaaa5bfd7e99c1a6cb02aa0a5cff90d48"
+ resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz"
integrity sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==
dependencies:
asynckit "^0.4.0"
@@ -3085,12 +3085,12 @@ micromatch@^4.0.4, micromatch@^4.0.8:
mime-db@1.52.0:
version "1.52.0"
- resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"
+ resolved "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz"
integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==
mime-types@^2.1.12:
version "2.1.35"
- resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a"
+ resolved "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz"
integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==
dependencies:
mime-db "1.52.0"
@@ -3677,7 +3677,7 @@ pretty-format@^3.8.0:
prisma@^6.1.0:
version "6.1.0"
- resolved "https://registry.yarnpkg.com/prisma/-/prisma-6.1.0.tgz#738f657fdd5ab8e6775f385db81bf7e61c70fbaf"
+ resolved "https://registry.npmjs.org/prisma/-/prisma-6.1.0.tgz"
integrity sha512-aFI3Yi+ApUxkwCJJwyQSwpyzUX7YX3ihzuHNHOyv4GJg3X5tQsmRaJEnZ+ZyfHpMtnyahhmXVfbTZ+lS8ZtfKw==
dependencies:
"@prisma/engines" "6.1.0"