Skip to content

Commit

Permalink
update Register and login form page and fix localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
satanakorn committed Nov 21, 2024
1 parent 2b1a4ef commit e522a96
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 27 deletions.
7 changes: 5 additions & 2 deletions frontend/src/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const LoginForm = () => {
try {
const response = await Axios.post('http://localhost:3000/user/login', formData);

console.log(response.data);


Swal.fire({
title: "Good job!",
text: "Login Sucessful!",
Expand All @@ -28,11 +31,11 @@ const LoginForm = () => {
Swal.close();
}, 3000);

await new Promise(resolve => setTimeout(resolve, 2000));
await new Promise(resolve => setTimeout(resolve, 750));

// Save token to localStorage and redirect
// localStorage.setItem('authToken', response.data.token);
localStorage.setItem('userID', response.data.UserID);
localStorage.setItem('UserID', JSON.stringify(response.data.UserID));
window.location.href = '/profile';
} catch (error) {
Swal.fire({
Expand Down
60 changes: 35 additions & 25 deletions frontend/src/Register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Register = () => {
userName:'',
email:'',
password:'',
confirmPassword:'',
ProfileImage:'',
workingStyle:'',
bio:'',
});
Expand All @@ -27,21 +27,22 @@ const Register = () => {
e.preventDefault();


if (formData.password !== formData.confirmPassword) {
Swal.fire({
title: "Error!",
text: "Passwords do not match!",
icon: "error",
});
return;
// if (formData.password !== formData.confirmPassword) {
// Swal.fire({
// title: "Error!",
// text: "Passwords do not match!",
// icon: "error",
// });
// return;

}
// }

try {
const response = await Axios.post('http://localhost:3000/user/create', {
userName: formData.userName,
email: formData.email,
password: formData.password,
ProfileImage: formData.ProfileImage,
workingStyle: formData.workingStyle,
bio: formData.bio,
});
Expand All @@ -55,7 +56,7 @@ const Register = () => {
userName: "",
email: "",
password: "",
confirmPassword: "",
ProfileImage: "",
workingStyle: "",
bio: "",
});
Expand All @@ -71,10 +72,11 @@ const Register = () => {

await new Promise(resolve => setTimeout(resolve, 2000));

localStorage.setItem('userID', JSON.stringify(response.data.UserID));
// localStorage.setItem('UserID', JSON.stringify(response.data.UserID));
window.location.href = '/login';

}

} catch (error) {
Swal.fire({
title: "Error!",
Expand Down Expand Up @@ -114,22 +116,17 @@ const Register = () => {
required
className="w-full h-12 px-4 py-2 bg-transparent border border-white rounded-full text-white placeholder-white focus:outline-none focus:border-white"
/>
<input
name="workingStyle"
type="text"
placeholder="Working Style"
value={formData.workingStyle}
onChange={handleInputChange}
className="w-full h-12 px-4 py-2 bg-transparent border border-white rounded-full text-white placeholder-white focus:outline-none focus:border-white"
/>

<textarea
name="bio"
placeholder="Short Description"
value={formData.bio}
onChange={handleInputChange}
className="w-full h-32 px-4 py-2 bg-transparent border border-white rounded-lg text-white placeholder-white focus:outline-none focus:border-white resize-none"
/>
<input


<input
name="password"
type="password"
placeholder="Password"
Expand All @@ -138,21 +135,34 @@ const Register = () => {
required
className="w-full h-12 px-4 py-2 bg-transparent border border-white rounded-full text-white placeholder-white focus:outline-none focus:border-white"
/>


<input
name="confirmPassword"
type="password"
placeholder="Confirm Password"
value={formData.confirmPassword}
name="ProfileImage"
type="file" // Changed to file input
onChange={handleInputChange}
required
className="w-full h-12 px-4 py-2 bg-transparent border border-white rounded-full text-white placeholder-white focus:outline-none focus:border-white"
/>

<input
name="workingStyle"
type="text"
placeholder="Working Style"
value={formData.workingStyle}
onChange={handleInputChange}
className="w-full h-12 px-4 py-2 bg-transparent border border-white rounded-full text-white placeholder-white focus:outline-none focus:border-white"
/>




</div>

{/* Submit button */}
<button
type="submit"
className="w-full h-12 bg-white text-black font-bold rounded-full shadow-md hover:bg-gray-200 transition duration-300"
className="mt-10 w-full h-12 bg-white text-black font-bold rounded-full shadow-md hover:bg-gray-200 transition duration-300"
>
Register
</button>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function Navbar() {
const handleLogout = () => {
localStorage.removeItem('userID');
setIsLoggedIn(false);
window.location.href = '/login';
};

return (
Expand Down

0 comments on commit e522a96

Please sign in to comment.