Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions apps/X/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<HomeRight />
<CenterComp />
<HomeLeft />
<HomeComp />
</div>
);
};
Expand Down
64 changes: 61 additions & 3 deletions apps/X/app/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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({
Expand Down Expand Up @@ -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;
Expand All @@ -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",
Expand Down
19 changes: 13 additions & 6 deletions apps/X/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 5 additions & 1 deletion apps/X/app/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
import { SessionProvider } from "next-auth/react";

export const Provider = ({ children }: { children: React.ReactNode }) => {
return <SessionProvider>{children}</SessionProvider>;
return (
<SessionProvider refetchInterval={0} refetchOnWindowFocus={false}>
{children}
</SessionProvider>
);
};
Binary file added apps/X/public/pnglogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 20 additions & 6 deletions apps/X/src/components/RouteGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TweetComp } from "../ui";


export const CenterComp = () => {
return (
<div>
Center Home
<TweetComp />
<div className=" border-slate-800 border border-y-0 h-screen ">
<TweetComp />
</div>
</div>
);
};
22 changes: 22 additions & 0 deletions apps/X/src/components/home/HomeComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HomeRight, Button, CenterComp, HomeLeft } from "@/components/ui";

export const HomeComp = () => {
return (
<div>
<div className="grid grid-cols-9">
<div className="col-span-1"></div>
<div className="col-span-2">
<HomeRight />
</div>
<div className="col-span-3">
<CenterComp />
</div>
{/* <div className="col-span-1"></div> */}
<div className="col-span-2">
<HomeLeft />
</div>
<div className="col-span-1"></div>
</div>
</div>
);
};
73 changes: 70 additions & 3 deletions apps/X/src/components/ui/TweetComp.tsx
Original file line number Diff line number Diff line change
@@ -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";
<RiShare2Line />;
export const TweetComp = () => {
return (
<div>
<UserAvatar />
<div className="">
<div className="flex p-3 gap-2">
<div className="mt-1">
<UserAvatar />
</div>
<div className="">
<div className="grid grid-cols-6">
<div className="flex col-span-5">
<p>username</p>
<p> @name</p>
<p> . time</p>
</div>
<p className="text-end">...</p>
</div>
<div className="flex flex-col">
<div className="list-inside">
#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
</div>
<div className="">Image Part</div>
</div>
{/* <div className="grid grid-cols-5 space-x-8">
<div className="flex col-span-1">
<FaRegComment />
</div>
<div className="flex col-span-1">
<BiRepost />
</div>
<div className="flex col-span-1">
<FiHeart />
</div>
<div className="flex col-span-1">
<IoIosStats />
</div>
<div className="flex">
<FaRegBookmark />
<RiShare2Line />
</div>
</div> */}

<div className="flex space-x-24">
<FaRegComment />
<BiRepost />
<FiHeart />
<IoIosStats />
{/* <div className="">
</div>
<div className="">
</div>
<div className="">
</div>
<div className="">
</div> */}
<div className="flex">
<FaRegBookmark />
<RiShare2Line />
</div>
</div>
</div>
</div>
</div>
);
};
2 changes: 1 addition & 1 deletion apps/X/src/components/ui/X_logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const X_logo = () => {
<svg
viewBox="0 0 24 24"
aria-hidden="true"
className=" w-min-6 h-min-6 fill-current text-black dark:text-white"
className=" w-6 h-6 fill-current text-black dark:text-white"
>
<g>
<path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"></path>
Expand Down
4 changes: 3 additions & 1 deletion apps/X/src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading