Skip to content

Commit 8d204b6

Browse files
authored
Merge pull request #53 from deepraj21/main
updated chat section and model
2 parents 6ef848e + 42b2192 commit 8d204b6

24 files changed

+2187
-577
lines changed

client/package-lock.json

Lines changed: 1236 additions & 62 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
"dependencies": {
1313
"@hookform/resolvers": "^3.9.0",
1414
"@radix-ui/react-accordion": "^1.2.0",
15+
"@radix-ui/react-avatar": "^1.1.1",
1516
"@radix-ui/react-dialog": "^1.1.1",
16-
"@radix-ui/react-dropdown-menu": "^2.1.1",
17+
"@radix-ui/react-dropdown-menu": "^2.1.2",
1718
"@radix-ui/react-icons": "^1.3.0",
1819
"@radix-ui/react-label": "^2.1.0",
1920
"@radix-ui/react-navigation-menu": "^1.2.0",
21+
"@radix-ui/react-scroll-area": "^1.2.0",
2022
"@radix-ui/react-select": "^2.1.1",
2123
"@radix-ui/react-slot": "^1.1.0",
2224
"@radix-ui/react-toast": "^1.2.1",
@@ -38,13 +40,15 @@
3840
"react-dom": "^18.3.1",
3941
"react-hook-form": "^7.52.1",
4042
"react-icons": "^5.3.0",
43+
"react-markdown": "^9.0.1",
4144
"react-redux": "^9.1.2",
4245
"react-router-dom": "^6.25.1",
4346
"react-wrap-balancer": "^1.1.1",
4447
"redux": "^5.0.1",
4548
"sonner": "^1.5.0",
4649
"tailwind-merge": "^2.4.0",
4750
"tailwindcss-animate": "^1.0.7",
51+
"typewriter-effect": "^2.21.0",
4852
"vaul": "^0.9.1",
4953
"zod": "^3.23.8"
5054
},

client/src/App.tsx

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,18 @@ import Home from './pages/Home';
1010
import Profile from './pages/Profile';
1111
import { Toaster } from "@/components/ui/sonner";
1212

13-
const backendUrl = import.meta.env.VITE_BACKEND_URL || 'http://localhost:5000';
14-
1513
const App: React.FC = () => {
16-
const [authenticated, setAuthenticated] = useState(false);
17-
const [username, setUsername] = useState<string | null>(null);
18-
19-
useEffect(() => {
20-
const checkAuth = async () => {
21-
try {
22-
const response = await axios.get(`${backendUrl}/check_auth`, { withCredentials: true });
23-
if (response.data.authenticated) {
24-
setAuthenticated(true);
25-
setUsername(response.data.username);
26-
} else {
27-
setAuthenticated(false);
28-
}
29-
} catch (error) {
30-
console.error('Failed to check authentication status:', error);
31-
}
32-
};
33-
34-
checkAuth();
35-
}, []);
36-
37-
const handleLogout = async () => {
38-
try {
39-
const response = await axios.get(`${backendUrl}/logout`, { withCredentials: true });
40-
if (response.data.message === 'Logout successful') {
41-
setAuthenticated(false);
42-
setUsername(null);
43-
}
44-
} catch (error) {
45-
console.error('Failed to logout:', error);
46-
}
47-
};
4814

4915
return (
5016
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
5117
<Router>
5218
<Routes>
53-
<Route path="/" element={authenticated ? <Navigate to="/home" /> : <Landing />} />
19+
<Route path="/" element={<Landing />} />
5420
<Route path="/signup" element={<Signup />} />
55-
<Route path="/login" element={<Login onLoginSuccess={(username: string) => { setAuthenticated(true); setUsername(username); }} />} />
56-
<Route path="/home" element={authenticated ? <Home onLogout={handleLogout} username={username || ''} /> : <Navigate to="/" />} />
57-
<Route path="/u/:username" element={<Profile onLogout={handleLogout} username={username || ''} />} />
58-
<Route path="*" element={<Navigate to="/" />} />
21+
<Route path="/login" element={<Login />} />
22+
<Route path="/home" element={<Home />} />
23+
<Route path="/u/:username" element={<Profile />} />
24+
<Route path="*" element={<div>404</div>} />
5925
</Routes>
6026
</Router>
6127
<Toaster />

client/src/components/Auth/user-auth-form-login.tsx

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
"use client";
2-
31
import React, { useState } from 'react';
4-
import axios from 'axios';
52
import { useNavigate } from 'react-router-dom';
63
import { toast } from "sonner";
74

@@ -13,11 +10,7 @@ import { Label } from "@/components/ui/label";
1310

1411
const backendUrl = import.meta.env.VITE_BACKEND_URL || 'http://localhost:5000';
1512

16-
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> {
17-
onLoginSuccess?: (username: string) => void;
18-
}
19-
20-
export function UserAuthForm({ className, onLoginSuccess, ...props }: UserAuthFormProps) {
13+
export function UserAuthForm() {
2114
const [isLoading, setIsLoading] = useState<boolean>(false);
2215
const [username, setUsername] = useState<string>('');
2316
const [password, setPassword] = useState<string>('');
@@ -28,42 +21,44 @@ export function UserAuthForm({ className, onLoginSuccess, ...props }: UserAuthFo
2821
setIsLoading(true);
2922

3023
try {
31-
const response = await axios.post(`${backendUrl}/login`, { username, password }, { withCredentials: true });
32-
if (response.status === 200) {
24+
const response = await fetch(`${backendUrl}/login`, {
25+
method: 'POST',
26+
headers: {
27+
'Content-Type': 'application/json',
28+
},
29+
credentials: 'include',
30+
body: JSON.stringify({ username, password }),
31+
});
3332

33+
if (response.ok) {
3434
localStorage.setItem('devhub_username', username);
35-
36-
if (onLoginSuccess) {
37-
onLoginSuccess(username);
38-
}
3935
navigate('/home');
40-
}
41-
} catch (err: any) {
42-
if (err.response && err.response.data && err.response.data.message) {
43-
toast.error(err.response.data.message, {
44-
description: "Please check your details and try again.",
45-
action: {
46-
label: "Try again",
47-
onClick: () => console.log("Try again clicked"),
48-
},
49-
});
5036
} else {
51-
toast.error("Login failed", {
52-
description: "There was a problem with your request.",
37+
const errorData = await response.json();
38+
toast.error(errorData.message || "Login failed", {
39+
description: "Please check your details and try again.",
5340
action: {
5441
label: "Try again",
5542
onClick: () => console.log("Try again clicked"),
5643
},
5744
});
5845
}
59-
console.error('Login error:', err);
46+
} catch (error) {
47+
toast.error("Login failed", {
48+
description: "There was a problem with your request.",
49+
action: {
50+
label: "Try again",
51+
onClick: () => console.log("Try again clicked"),
52+
},
53+
});
54+
console.error('Login error:', error);
6055
} finally {
6156
setIsLoading(false);
6257
}
6358
}
6459

6560
return (
66-
<div className={cn("grid gap-6", className)} {...props}>
61+
<div className={cn("grid gap-6")}>
6762
<form onSubmit={onSubmit}>
6863
<div className="grid gap-2">
6964
<div className="grid gap-1">

client/src/components/Auth/user-auth-form-signup.tsx

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

33
import React, { useState, useEffect } from "react";
4-
import axios from "axios";
54
import { useNavigate } from "react-router-dom";
65
import { toast } from "sonner";
76

@@ -11,7 +10,7 @@ import { Button } from "@/components/ui/button";
1110
import { Input } from "@/components/ui/input";
1211
import { Label } from "@/components/ui/label";
1312

14-
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> {}
13+
interface UserAuthFormProps extends React.HTMLAttributes<HTMLDivElement> { }
1514
interface PasswordRules {
1615
minLength: boolean;
1716
containsUpper: boolean;
@@ -26,18 +25,15 @@ const backendUrl = import.meta.env.VITE_BACKEND_URL || "http://localhost:5000";
2625
export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
2726
const [isLoading, setIsLoading] = useState<boolean>(false);
2827
const [username, setUsername] = useState<string>("");
29-
const [isUsernameAvailable, setIsUsernameAvailable] = useState<
30-
boolean | null
31-
>(null);
28+
const [isUsernameAvailable, setIsUsernameAvailable] = useState<boolean | null>(null);
3229
const [email, setEmail] = useState<string>("");
3330
const [password, setPassword] = useState<string>("");
3431
const [usernameError, setUsernameError] = useState<string>("");
35-
const [passwordRules, setPasswordRules] = useState<PasswordRules | null>(
36-
null
37-
);
32+
const [passwordRules, setPasswordRules] = useState<PasswordRules | null>(null);
3833
const [isPasswordValid, setIsPasswordValid] = useState<boolean>(false);
39-
const navigate = useNavigate(); // Hook for navigation
34+
const navigate = useNavigate();
4035

36+
// Username availability check with debounce
4137
useEffect(() => {
4238
const checkUsernameAvailability = async () => {
4339
if (username) {
@@ -56,10 +52,10 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
5652
return;
5753
}
5854
setUsernameError("");
59-
const response = await axios.get(`${backendUrl}/check_username`, {
60-
params: { username },
61-
});
62-
setIsUsernameAvailable(response.data.available);
55+
56+
const response = await fetch(`${backendUrl}/check_username?username=${username}`);
57+
const data = await response.json();
58+
setIsUsernameAvailable(data.available);
6359
} catch (error) {
6460
console.error("Error checking username availability:", error);
6561
}
@@ -76,6 +72,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
7672
return () => clearTimeout(delayDebounceFn);
7773
}, [username]);
7874

75+
// Password validation rules
7976
const validatePassword = (password: string): PasswordRules => {
8077
return {
8178
minLength: password.length >= 6,
@@ -107,6 +104,7 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
107104
noWhitespace: "Should not contain spaces.",
108105
};
109106

107+
// Form submission handler
110108
async function onSubmit(event: React.SyntheticEvent) {
111109
event.preventDefault();
112110
setIsLoading(true);
@@ -116,34 +114,36 @@ export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
116114
}
117115

118116
try {
119-
await axios.post(`${backendUrl}/signup`, { username, email, password });
117+
const response = await fetch(`${backendUrl}/signup`, {
118+
method: "POST",
119+
headers: {
120+
"Content-Type": "application/json",
121+
},
122+
body: JSON.stringify({ username, email, password }),
123+
});
124+
125+
if (!response.ok) {
126+
const errorData = await response.json();
127+
throw new Error(errorData.message || "Signup failed");
128+
}
129+
120130
toast.success("Signup successful", {
121131
description: "You can now log in with your new account.",
122132
action: {
123133
label: "Login",
124134
onClick: () => navigate("/login"),
125135
},
126136
});
127-
navigate("/login"); // Redirect to login page on successful signup
128-
} catch (err: any) {
129-
if (err.response && err.response.data && err.response.data.message) {
130-
toast.error(err.response.data.message, {
131-
description: "Please check your details and try again.",
132-
action: {
133-
label: "Try again",
134-
onClick: () => console.log("Try again clicked"),
135-
},
136-
});
137-
} else {
138-
toast.error("Signup failed", {
139-
description: "There was a problem with your request.",
140-
action: {
141-
label: "Try again",
142-
onClick: () => console.log("Try again clicked"),
143-
},
144-
});
145-
}
146-
console.error("Error during signup:", err);
137+
navigate("/login");
138+
} catch (error) {
139+
toast.error(`Signup failed ${error}`, {
140+
description: "Please check your details and try again.",
141+
action: {
142+
label: "Try again",
143+
onClick: () => console.log("Try again clicked"),
144+
},
145+
});
146+
console.error("Error during signup:", error);
147147
} finally {
148148
setIsLoading(false);
149149
}

0 commit comments

Comments
 (0)