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
12 changes: 12 additions & 0 deletions apps/X/app/home/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CenterComp, HomeLeft, HomeRight } from "@/components/ui";

const homepage = () => {
return (
<div>
<HomeRight />
<CenterComp />
<HomeLeft />
</div>
);
};
export default homepage;
20 changes: 9 additions & 11 deletions apps/X/app/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,44 +53,45 @@ export const authOptions = {
});
};

console.log(credentials, "User credentilas");

if (!validatedUserInput) return null;

const hashedPassword = await bcrypt.hash(credentials.password, 10);

const existingUser = await db.user.findFirst({
where: {
username: credentials.username,
email: credentials.email,
// email: credentials.email,
},
});

if (existingUser) {
try {
console.log("This is old user");

const passwordValidation = await bcrypt.compare(
credentials.password,
existingUser.password
);
console.log("This is the password", passwordValidation);
if (passwordValidation) {
console.log("This is userEmail", existingUser.email);
console.log("This is username", existingUser.username);
return {
id: existingUser?.id.toString(),
usernname: existingUser.username,
email: existingUser.email,
name: existingUser.name,
};
}

console.log("This is name", existingUser.name);
} catch (error) {
console.log(error, "Error while LogIn");
console.log("Error while LogIn", error);
}
return null;
}

try {
console.log("Creating New User....");

const user = await db.user.create({
data: {
username: credentials.username,
Expand All @@ -103,7 +104,6 @@ export const authOptions = {
id: user.id.toString(),
name: user.name,
username: user.username,
email: user.email,
};
} catch (error) {
console.log(error, "Not able to Create new user");
Expand All @@ -117,8 +117,6 @@ export const authOptions = {

callbacks: {
async jwt({ token }: { token: JWT }) {
console.log(token, "this is the userToken");

return token;
},

Expand All @@ -131,7 +129,7 @@ export const authOptions = {
if (token) {
session.accessToken = token.accessToken;
console.log(session.accessToken, " This is from the sesson function 1");
session.userid = token.sub;
session.user.id = token.sub;
console.log(session.userid, " This is from the sesson function 2");
}
return session;
Expand Down
24 changes: 14 additions & 10 deletions apps/X/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { SigninComp } from "@/components/ui";
import React from "react";

const Page = () => {
return (
<div className="">
<SigninComp />
</div>
);
import { getServerSession } from "next-auth";
import { authOptions } from "./lib/auth";
import { redirect } from "next/navigation";

const Page = async () => {
const session = await getServerSession(authOptions);

if (!session?.user) {
console.log("This is the User session >>>>>>>>>>>>>>>>>", session?.user);

redirect("/signin");
} else {
redirect("/home");
}
};

export default Page;
Page;
3 changes: 3 additions & 0 deletions apps/X/src/components/home/CenterComp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CenterComp = () => {
return <div>Center Home</div>;
};
3 changes: 3 additions & 0 deletions apps/X/src/components/home/HomeLeft.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const HomeLeft = () => {
return <div>Home Left</div>;
};
3 changes: 3 additions & 0 deletions apps/X/src/components/home/HomeRight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const HomeRight = () => {
return <div>Home Right Side</div>;
};
27 changes: 15 additions & 12 deletions apps/X/src/components/ui/LoginComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@ import Link from "next/link";
export const LoginComp = () => {
const [formData, setFormData] = useState({
username: "",
name: "",
email: "",
password: "",
});

const [error, setError] = useState("");

const handelFormChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFormData({
...formData,
[e.target.name]: e.target.value,
});
};

const handelCredentialSignin = async () => {
const handleGoogleSignIn = async () => {
await signIn("google");
};
const handleGithubSignIn = async () => {
await signIn("github");
};

const handelCredentialLogin = async () => {
console.log("Reaching here");
try {
console.log("Reaching here");
console.log("Login Components Reaching here");

await signIn("credentials", {
const result = await signIn("credentials", {
username: formData.username,
email: formData.email,
name: formData.name,
password: formData.password,
});
} catch (error) {
Expand All @@ -44,23 +49,21 @@ export const LoginComp = () => {
<div className="">
<X_logo />
</div>

<div className="w-72">
<div className="text-xl my-4 ">Sign in to 𝕏 </div>

<div className="">
<div className="">
<div className="flex flex-col justify-start items-start">
<Button
className="w-full rounded-2xl"
// onClick={handleGoogleSignIn}
onClick={handleGoogleSignIn}
>
{" "}
<FcGoogle /> Sign UP with Google{" "}
</Button>
<Button
className="mt-2 w-full rounded-2xl font-bold"
// onClick={handleGithubSignIn}
onClick={handleGithubSignIn}
>
{" "}
<FaGithub /> Sign UP with Github{" "}
Expand Down Expand Up @@ -96,7 +99,7 @@ export const LoginComp = () => {

<Button
className="w-full rounded-2xl font-bold text-twitterBlue"
onClick={handelCredentialSignin}
onClick={handelCredentialLogin}
>
Login
</Button>
Expand Down
6 changes: 6 additions & 0 deletions apps/X/src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { X_logo } from "./X_logo";
import { Input } from "./input";
import { LoginComp } from "./LoginComp";
import { UserCredentials } from "./UserCredentials";
import { HomeRight } from "../home/HomeRight";
import { HomeLeft } from "../home/HomeLeft";
import { CenterComp } from "../home/CenterComp";

export {
SigninComp,
Expand All @@ -16,6 +19,9 @@ export {
Dialog,
X_logo,
Input,
HomeRight,
HomeLeft,
CenterComp,
UserCredentials,
LoginComp,
};
Loading