diff --git a/apps/X/app/home/page.tsx b/apps/X/app/home/page.tsx
index c0d1a0f..56c4c20 100644
--- a/apps/X/app/home/page.tsx
+++ b/apps/X/app/home/page.tsx
@@ -1,16 +1,10 @@
"use client";
-import { HomeRight, Button, CenterComp, HomeLeft } from "@/components/ui";
-import { signOut } from "next-auth/react";
+import { HomeComp } from "@/components/ui";
const homepage = () => {
- const handleLogout = async () => {
- await signOut({ callbackUrl: "/" });
- };
return (
-
-
-
+
);
};
diff --git a/apps/X/app/lib/auth.ts b/apps/X/app/lib/auth.ts
index 1c1acf6..9cfc0e8 100644
--- a/apps/X/app/lib/auth.ts
+++ b/apps/X/app/lib/auth.ts
@@ -4,7 +4,7 @@ import { JWT } from "next-auth/jwt";
import CredentialsProvider from "next-auth/providers/credentials";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
-import { signOut } from "next-auth/react";
+import { signIn, signOut } from "next-auth/react";
import z from "zod";
interface credentialsTypes {
@@ -26,10 +26,28 @@ export const authOptions = {
GithubProvider({
clientId: process.env.GITHUB_ID || "",
clientSecret: process.env.GITHUB_SECRET || "",
+ profile(profile) {
+ return {
+ id: profile.id.toString(),
+ name: profile.name || profile.login,
+ email: profile.email,
+ username: profile.login,
+ image: profile.avatar_url,
+ };
+ },
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID || "",
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
+ profile(profile) {
+ return {
+ id: profile.sub,
+ name: profile.name,
+ email: profile.email,
+ username: profile.email.split("@")[0],
+ image: profile.picture,
+ };
+ },
}),
CredentialsProvider({
@@ -118,10 +136,12 @@ export const authOptions = {
},
}),
],
- Secret: process.env.NEXTAUTH_SECRET || "secr3t",
+ secret: process.env.NEXTAUTH_SECRET || "secr3t",
callbacks: {
- async jwt({ token, user }: any) {
+ async jwt({ token, user, account }: any) {
+ console.log("JWT Callback - User:", user);
+ console.log("JWT Callback - Account:", account);
if (user) {
token.id = user.id;
token.username = user.username;
@@ -141,6 +161,44 @@ export const authOptions = {
}
return session;
},
+
+ async signIn({ user, profile, account }: any) {
+ try {
+ const existingUser = await db.user.findFirst({
+ where: {
+ OR: [{ email: user.email }, { username: user.username }],
+ },
+ });
+
+ if (!existingUser) {
+ await db.user.create({
+ data: {
+ // Make sure this matches your DB schema
+ username:
+ user.username ||
+ (account.provider === "github"
+ ? profile.login
+ : profile.email.split("@")[0]),
+ email: user.email || `${user.id}@${account.provider}.user`,
+ name: user.name,
+ password: "",
+ // image: user.image,
+ },
+ });
+ console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
+
+ console.log({
+ id: user.id.toString(),
+ name: user.name,
+ username: user.username,
+ });
+ }
+ return true;
+ } catch (error) {
+ console.error("SignIn Error ", error);
+ return false;
+ }
+ },
},
pages: {
signIn: "/signin",
diff --git a/apps/X/app/page.tsx b/apps/X/app/page.tsx
index b678fa6..826b48a 100644
--- a/apps/X/app/page.tsx
+++ b/apps/X/app/page.tsx
@@ -3,15 +3,22 @@ import { authOptions } from "./lib/auth";
import { redirect } from "next/navigation";
const Page = async () => {
- const session = await getServerSession(authOptions);
- console.log(session, "This is the session log");
+ console.log(">>>>>>>>>>>>>>>");
+ try {
+ const session = await getServerSession(authOptions);
+ console.log("Full session object:", JSON.stringify(session, null, 2));
- if (!session?.user?.id) {
- console.log("No valid session, redirecting to signin");
+ if (!session?.user?.id) {
+ console.log("No valid session, redirecting to signin");
+ redirect("/signin");
+ }
+
+ console.log("Valid session detected, user:", session.user);
+ redirect("/home");
+ } catch (error) {
+ console.error("Error in root page:", error);
redirect("/signin");
}
- console.log("Valid session detected, redirecting to /home");
- redirect("/home");
};
export default Page;
diff --git a/apps/X/app/provider.tsx b/apps/X/app/provider.tsx
index 4d564ee..68e28a7 100644
--- a/apps/X/app/provider.tsx
+++ b/apps/X/app/provider.tsx
@@ -2,5 +2,9 @@
import { SessionProvider } from "next-auth/react";
export const Provider = ({ children }: { children: React.ReactNode }) => {
- return {children} ;
+ return (
+
+ {children}
+
+ );
};
diff --git a/apps/X/public/pnglogo.png b/apps/X/public/pnglogo.png
new file mode 100644
index 0000000..7d11571
Binary files /dev/null and b/apps/X/public/pnglogo.png differ
diff --git a/apps/X/src/components/RouteGuard.tsx b/apps/X/src/components/RouteGuard.tsx
index 6666248..29381a4 100644
--- a/apps/X/src/components/RouteGuard.tsx
+++ b/apps/X/src/components/RouteGuard.tsx
@@ -10,12 +10,26 @@ export function RouteGard({ children }: { children: React.ReactNode }) {
const router = useRouter();
const pathname = usePathname();
useEffect(() => {
- if (status == "loading") {
- return;
- }
- if (!session && !publicPaths.includes(pathname)) {
- router.push("/signin");
- }
+ const handleRouting = async () => {
+ try {
+ if (status === "loading") return;
+
+ if (!session && !publicPaths.includes(pathname)) {
+ console.log("No session, redirecting to signin");
+ await router.replace("/signin");
+ return;
+ }
+
+ if (session && publicPaths.includes(pathname)) {
+ console.log("Session exists, redirecting to home");
+ await router.replace("/home");
+ }
+ } catch (error) {
+ console.error("RouteGuard error:", error);
+ }
+ };
+
+ handleRouting();
}, [session, status, router, pathname]);
if (status == "loading") {
diff --git a/apps/X/src/components/home/HomeCenterComp.tsx b/apps/X/src/components/home/CenterComp.tsx
similarity index 51%
rename from apps/X/src/components/home/HomeCenterComp.tsx
rename to apps/X/src/components/home/CenterComp.tsx
index 3a1a6c2..e633dd4 100644
--- a/apps/X/src/components/home/HomeCenterComp.tsx
+++ b/apps/X/src/components/home/CenterComp.tsx
@@ -1,11 +1,11 @@
import { TweetComp } from "../ui";
-
export const CenterComp = () => {
return (
);
};
diff --git a/apps/X/src/components/home/HomeComp.tsx b/apps/X/src/components/home/HomeComp.tsx
new file mode 100644
index 0000000..692f4eb
--- /dev/null
+++ b/apps/X/src/components/home/HomeComp.tsx
@@ -0,0 +1,22 @@
+import { HomeRight, Button, CenterComp, HomeLeft } from "@/components/ui";
+
+export const HomeComp = () => {
+ return (
+
+
+
+
+
+
+
+
+
+ {/*
*/}
+
+
+
+
+
+
+ );
+};
diff --git a/apps/X/src/components/ui/TweetComp.tsx b/apps/X/src/components/ui/TweetComp.tsx
index 7126455..812e8d5 100644
--- a/apps/X/src/components/ui/TweetComp.tsx
+++ b/apps/X/src/components/ui/TweetComp.tsx
@@ -1,9 +1,76 @@
+import { FaRegComment } from "react-icons/fa6";
+import { BiRepost } from "react-icons/bi";
import { UserAvatar } from "./usrAvatar";
-
+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
+
+ {/*
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
*/}
+
+
+
+
+
+
+ {/*
+
+
+
+
+
+
+
*/}
+
+
+
+
+
+
+
);
};
diff --git a/apps/X/src/components/ui/X_logo.tsx b/apps/X/src/components/ui/X_logo.tsx
index 0914049..7fcfeb7 100644
--- a/apps/X/src/components/ui/X_logo.tsx
+++ b/apps/X/src/components/ui/X_logo.tsx
@@ -5,7 +5,7 @@ export const X_logo = () => {
diff --git a/apps/X/src/components/ui/index.ts b/apps/X/src/components/ui/index.ts
index 7f87b3c..14107a6 100644
--- a/apps/X/src/components/ui/index.ts
+++ b/apps/X/src/components/ui/index.ts
@@ -8,13 +8,15 @@ import { LoginComp } from "./LoginComp";
import { UserCredentials } from "./UserCredentials";
import { HomeRight } from "../home/HomeRight";
import { HomeLeft } from "../home/HomeLeft";
-import { CenterComp } from "../home/HomeCenterComp";
+import { CenterComp } from "../home/CenterComp";
import { TweetComp } from "./TweetComp";
import { UserAvatar } from "./usrAvatar";
import { Button } from "./button";
+import { HomeComp } from "../home/HomeComp";
export {
SigninComp,
+ HomeComp,
Button,
UserAvatar,
SigninRightCom,