Skip to content

Commit 2ad4ee3

Browse files
authored
Merge pull request #16 from mscode07/dev
fixed the backend issue signin
2 parents 4976036 + 04cfbf6 commit 2ad4ee3

File tree

7 files changed

+89
-9080
lines changed

7 files changed

+89
-9080
lines changed

apps/X/app/lib/auth.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import db from "@repo/db/client";
22
import bcrypt from "bcrypt";
33
import { JWT } from "next-auth/jwt";
4-
54
import CredentialsProvider from "next-auth/providers/credentials";
65
import GithubProvider from "next-auth/providers/github";
76
import GoogleProvider from "next-auth/providers/google";
@@ -59,7 +58,6 @@ export const authOptions = {
5958
if (!validatedUserInput) return null;
6059

6160
const hashedPassword = await bcrypt.hash(credentials.password, 10);
62-
console.log(hashedPassword);
6361

6462
const existingUser = await db.user.findFirst({
6563
where: {
@@ -70,6 +68,8 @@ export const authOptions = {
7068

7169
if (existingUser) {
7270
try {
71+
console.log("This is old user");
72+
7373
const passwordValidation = await bcrypt.compare(
7474
credentials.password,
7575
existingUser.password
@@ -89,6 +89,8 @@ export const authOptions = {
8989
}
9090

9191
try {
92+
console.log("Creating New User....");
93+
9294
const user = await db.user.create({
9395
data: {
9496
username: credentials.username,

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ export const SigninRightCom = () => {
5252
<p className="px-2 text-slate-500">or</p>
5353
<hr className="w-72 h-0.5 my-4 bg-gray-200 border-0 rounded dark:bg-gray-700"></hr>
5454
</div>
55-
{/* <Button
56-
className="bg-twitterBlue hover:bg-blue-500 px-24 mt-0 rounded-2xl text-white"
57-
onClick={handleCredentialsSignIn}
58-
>
59-
Create Account
60-
</Button> */}
6155
<Dialog>
6256
<DialogTrigger className="bg-twitterBlue hover:bg-blue-500 py-1 px-24 mt-0 rounded-2xl text-white">
6357
Create Account
@@ -77,12 +71,7 @@ export const SigninRightCom = () => {
7771
<span className="text-twitterBlue"> Cookie Use.</span>
7872
</p>
7973
<div className="mt-12 font-semibold">Already have an account?</div>
80-
{/* <Button
81-
variant={"outline"}
82-
className="mt-3 px-28 rounded-2xl text-twitterBlue"
83-
>
84-
Sign In
85-
</Button> */}
74+
8675
<Dialog>
8776
<DialogTrigger className=" border border-slate-500 py-1 px-24 mt-1 rounded-2xl text-twitterBlue font-semibold hover:bg-slate-900 ">
8877
Sign In

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1+
"use client";
12
import { signIn } from "next-auth/react";
3+
import { useState } from "react";
24
import { Button } from "./button";
35
import { Input } from "./index";
46
import { X_logo } from "./X_logo";
57

68
export const UserCredentials = () => {
7-
const handleCredentialsSignIn = () => {
8-
signIn("credentials");
9+
const [formData, setFormData] = useState({
10+
username: "",
11+
name: "",
12+
email: "",
13+
password: "",
14+
});
15+
16+
const handelFormChange = (e: React.ChangeEvent<HTMLInputElement>) => {
17+
setFormData({
18+
...formData,
19+
[e.target.name]: e.target.value,
20+
});
921
};
22+
23+
const handelCredentialSignin = async () => {
24+
console.log("Reaching here");
25+
try {
26+
console.log("Reaching here");
27+
28+
await signIn("credentials", {
29+
username: formData.username,
30+
email: formData.email,
31+
name: formData.name,
32+
password: formData.password,
33+
});
34+
} catch (error) {
35+
console.log(error, "Error with Credentials");
36+
}
37+
};
38+
1039
return (
1140
<div>
1241
<div className="">
@@ -20,26 +49,38 @@ export const UserCredentials = () => {
2049
type="text"
2150
placeholder="Username"
2251
className="m-4 focus:border-blue-500"
52+
value={formData.username}
53+
onChange={handelFormChange}
54+
name="username"
2355
/>
2456
<Input
2557
type="text"
2658
placeholder="Name"
2759
className="m-4 focus:border-blue-500"
60+
value={formData.name}
61+
onChange={handelFormChange}
62+
name="name"
2863
/>
2964
<Input
3065
type="text"
3166
placeholder="Email"
3267
className="m-4 focus:border-blue-500"
68+
value={formData.email}
69+
onChange={handelFormChange}
70+
name="email"
3371
/>
3472
<Input
35-
type="passowrd"
73+
type="password"
3674
placeholder="Password"
3775
className="m-4 focus:border-blue-500"
76+
value={formData.password}
77+
onChange={handelFormChange}
78+
name="password"
3879
/>
3980
</div>
4081
<Button
4182
className="w-full ml-4 rounded-2xl font-bold text-twitterBlue"
42-
onClick={handleCredentialsSignIn}
83+
onClick={handelCredentialSignin}
4384
>
4485
Create Account
4586
</Button>

0 commit comments

Comments
 (0)