Skip to content

Commit f5fc4fb

Browse files
committed
fixing bugs
1 parent 9c39090 commit f5fc4fb

File tree

11 files changed

+205
-31
lines changed

11 files changed

+205
-31
lines changed

apps/X/app/home/page.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
"use client";
22

3-
import { HomeRight, Button, CenterComp, HomeLeft } from "@/components/ui";
3+
import { HomeComp } from "@/components/ui";
4+
import { HomeIcon } from "lucide-react";
45
import { signOut } from "next-auth/react";
56
const homepage = () => {
6-
const handleLogout = async () => {
7-
await signOut({ callbackUrl: "/" });
8-
};
97
return (
108
<div>
11-
<HomeRight />
12-
<CenterComp />
13-
<HomeLeft />
9+
<HomeComp />
1410
</div>
1511
);
1612
};

apps/X/app/lib/auth.ts

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { JWT } from "next-auth/jwt";
44
import CredentialsProvider from "next-auth/providers/credentials";
55
import GithubProvider from "next-auth/providers/github";
66
import GoogleProvider from "next-auth/providers/google";
7-
import { signOut } from "next-auth/react";
7+
import { signIn, signOut } from "next-auth/react";
88
import z from "zod";
99

1010
interface credentialsTypes {
@@ -26,10 +26,28 @@ export const authOptions = {
2626
GithubProvider({
2727
clientId: process.env.GITHUB_ID || "",
2828
clientSecret: process.env.GITHUB_SECRET || "",
29+
profile(profile) {
30+
return {
31+
id: profile.id.toString(),
32+
name: profile.name || profile.login,
33+
email: profile.email,
34+
username: profile.login,
35+
image: profile.avatar_url,
36+
};
37+
},
2938
}),
3039
GoogleProvider({
3140
clientId: process.env.GOOGLE_CLIENT_ID || "",
3241
clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
42+
profile(profile) {
43+
return {
44+
id: profile.sub,
45+
name: profile.name,
46+
email: profile.email,
47+
username: profile.email.split("@")[0],
48+
image: profile.picture,
49+
};
50+
},
3351
}),
3452

3553
CredentialsProvider({
@@ -118,10 +136,12 @@ export const authOptions = {
118136
},
119137
}),
120138
],
121-
Secret: process.env.NEXTAUTH_SECRET || "secr3t",
139+
secret: process.env.NEXTAUTH_SECRET || "secr3t",
122140

123141
callbacks: {
124-
async jwt({ token, user }: any) {
142+
async jwt({ token, user, account }: any) {
143+
console.log("JWT Callback - User:", user);
144+
console.log("JWT Callback - Account:", account);
125145
if (user) {
126146
token.id = user.id;
127147
token.username = user.username;
@@ -141,6 +161,48 @@ export const authOptions = {
141161
}
142162
return session;
143163
},
164+
165+
async signIn({ user, profile, account }: any) {
166+
try {
167+
const existingUser = await db.user.findFirst({
168+
where: {
169+
OR: [{ email: user.email }, { username: user.username }],
170+
},
171+
});
172+
173+
if (!existingUser) {
174+
await db.user.create({
175+
data: {
176+
// Make sure this matches your DB schema
177+
username:
178+
user.username ||
179+
(account.provider === "github"
180+
? profile.login
181+
: profile.email.split("@")[0]),
182+
email: user.email || `${user.id}@${account.provider}.user`,
183+
name: user.name,
184+
password: "",
185+
// image: user.image,
186+
},
187+
});
188+
console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
189+
190+
console.log({
191+
id: user.id.toString(),
192+
name: user.name,
193+
username: user.username,
194+
});
195+
}
196+
return {
197+
id: user.id.toString(),
198+
name: user.name,
199+
username: user.username,
200+
};
201+
} catch (error) {
202+
console.error("SignIn Error ", error);
203+
return false;
204+
}
205+
},
144206
},
145207
pages: {
146208
signIn: "/signin",

apps/X/app/page.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,22 @@ import { authOptions } from "./lib/auth";
33
import { redirect } from "next/navigation";
44

55
const Page = async () => {
6-
const session = await getServerSession(authOptions);
7-
console.log(session, "This is the session log");
6+
console.log(">>>>>>>>>>>>>>>");
7+
try {
8+
const session = await getServerSession(authOptions);
9+
console.log("Full session object:", JSON.stringify(session, null, 2));
810

9-
if (!session?.user?.id) {
10-
console.log("No valid session, redirecting to signin");
11+
if (!session?.user?.id) {
12+
console.log("No valid session, redirecting to signin");
13+
redirect("/signin");
14+
}
15+
16+
console.log("Valid session detected, user:", session.user);
17+
redirect("/home");
18+
} catch (error) {
19+
console.error("Error in root page:", error);
1120
redirect("/signin");
1221
}
13-
console.log("Valid session detected, redirecting to /home");
14-
redirect("/home");
1522
};
1623

1724
export default Page;

apps/X/app/provider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
import { SessionProvider } from "next-auth/react";
33

44
export const Provider = ({ children }: { children: React.ReactNode }) => {
5-
return <SessionProvider>{children}</SessionProvider>;
5+
return (
6+
<SessionProvider refetchInterval={0} refetchOnWindowFocus={false}>
7+
{children}
8+
</SessionProvider>
9+
);
610
};

apps/X/public/pnglogo.png

179 KB
Loading

apps/X/src/components/RouteGuard.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,26 @@ export function RouteGard({ children }: { children: React.ReactNode }) {
1010
const router = useRouter();
1111
const pathname = usePathname();
1212
useEffect(() => {
13-
if (status == "loading") {
14-
return;
15-
}
16-
if (!session && !publicPaths.includes(pathname)) {
17-
router.push("/signin");
18-
}
13+
const handleRouting = async () => {
14+
try {
15+
if (status === "loading") return;
16+
17+
if (!session && !publicPaths.includes(pathname)) {
18+
console.log("No session, redirecting to signin");
19+
await router.replace("/signin");
20+
return;
21+
}
22+
23+
if (session && publicPaths.includes(pathname)) {
24+
console.log("Session exists, redirecting to home");
25+
await router.replace("/home");
26+
}
27+
} catch (error) {
28+
console.error("RouteGuard error:", error);
29+
}
30+
};
31+
32+
handleRouting();
1933
}, [session, status, router, pathname]);
2034

2135
if (status == "loading") {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { TweetComp } from "../ui";
22

3-
43
export const CenterComp = () => {
54
return (
65
<div>
7-
Center Home
8-
<TweetComp />
6+
<div className=" border-slate-800 border border-y-0 h-screen ">
7+
<TweetComp />
8+
</div>
99
</div>
1010
);
1111
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { HomeRight, Button, CenterComp, HomeLeft } from "@/components/ui";
2+
3+
export const HomeComp = () => {
4+
return (
5+
<div>
6+
<div className="grid grid-cols-9">
7+
<div className="col-span-1"></div>
8+
<div className="col-span-2">
9+
<HomeRight />
10+
</div>
11+
<div className="col-span-3">
12+
<CenterComp />
13+
</div>
14+
{/* <div className="col-span-1"></div> */}
15+
<div className="col-span-2">
16+
<HomeLeft />
17+
</div>
18+
<div className="col-span-1"></div>
19+
</div>
20+
</div>
21+
);
22+
};
Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,76 @@
1+
import { FaRegComment } from "react-icons/fa6";
2+
import { BiRepost } from "react-icons/bi";
13
import { UserAvatar } from "./usrAvatar";
2-
4+
import { FiHeart } from "react-icons/fi";
5+
import { IoIosStats } from "react-icons/io";
6+
import { FaRegBookmark } from "react-icons/fa6";
7+
import { RiShare2Line } from "react-icons/ri";
8+
<RiShare2Line />;
39
export const TweetComp = () => {
410
return (
5-
<div>
6-
<UserAvatar />
11+
<div className="">
12+
<div className="flex p-3 gap-2">
13+
<div className="mt-1">
14+
<UserAvatar />
15+
</div>
16+
<div className="">
17+
<div className="grid grid-cols-6">
18+
<div className="flex col-span-5">
19+
<p>username</p>
20+
<p> @name</p>
21+
<p> . time</p>
22+
</div>
23+
<p className="text-end">...</p>
24+
</div>
25+
<div className="flex flex-col">
26+
<div className="list-inside">
27+
#day100 so finally I completed 100 day of code. Amazing journey
28+
amazing learning and amazing people I have got in this journey and
29+
here are some glimpse from the journey. Thank you everyone and
30+
specially @kirat_tw #100xdevs #buildinpublic #space
31+
#LearningJourney #WeekendPlans
32+
</div>
33+
<div className="">Image Part</div>
34+
</div>
35+
{/* <div className="grid grid-cols-5 space-x-8">
36+
<div className="flex col-span-1">
37+
<FaRegComment />
38+
</div>
39+
<div className="flex col-span-1">
40+
<BiRepost />
41+
</div>
42+
<div className="flex col-span-1">
43+
<FiHeart />
44+
</div>
45+
<div className="flex col-span-1">
46+
<IoIosStats />
47+
</div>
48+
<div className="flex">
49+
<FaRegBookmark />
50+
<RiShare2Line />
51+
</div>
52+
</div> */}
53+
54+
<div className="flex space-x-24">
55+
<FaRegComment />
56+
<BiRepost />
57+
<FiHeart />
58+
<IoIosStats />
59+
{/* <div className="">
60+
</div>
61+
<div className="">
62+
</div>
63+
<div className="">
64+
</div>
65+
<div className="">
66+
</div> */}
67+
<div className="flex">
68+
<FaRegBookmark />
69+
<RiShare2Line />
70+
</div>
71+
</div>
72+
</div>
73+
</div>
774
</div>
875
);
976
};

apps/X/src/components/ui/X_logo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const X_logo = () => {
55
<svg
66
viewBox="0 0 24 24"
77
aria-hidden="true"
8-
className=" w-min-6 h-min-6 fill-current text-black dark:text-white"
8+
className=" w-6 h-6 fill-current text-black dark:text-white"
99
>
1010
<g>
1111
<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>

0 commit comments

Comments
 (0)