-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated frontend and backend for sign up page
- Loading branch information
1 parent
31d97eb
commit 3ad9781
Showing
9 changed files
with
272 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import toast from "react-hot-toast"; | ||
import { useState } from "react"; | ||
|
||
const useSignup = () => { | ||
const [loading, setLoading] = useState(false); | ||
const signup = async ({ | ||
fullName, | ||
UserName, | ||
Password, | ||
ConfirmPassword, | ||
Gender, | ||
}) => { | ||
const success = handleInput({ | ||
fullName, | ||
UserName, | ||
Password, | ||
ConfirmPassword, | ||
Gender, | ||
}); | ||
if (!success) { | ||
console.log("Error in useSignup"); | ||
return; | ||
} | ||
try { | ||
setLoading(true); | ||
const res = await fetch("/api/auth/signup", { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
fullName, | ||
userName: UserName, | ||
password: Password, | ||
confirmPassword: ConfirmPassword, | ||
gender: Gender, | ||
}), | ||
}); | ||
const data = await res.json(); | ||
console.log(data); | ||
} catch (error) { | ||
toast.error(error.message); | ||
setLoading(false); | ||
console.log(error.message); | ||
return false; | ||
} | ||
}; | ||
return { loading, signup }; | ||
}; | ||
|
||
const handleInput = ({ | ||
fullName, | ||
UserName, | ||
Password, | ||
ConfirmPassword, | ||
Gender, | ||
}) => { | ||
if (!fullName || !UserName || !Password || !ConfirmPassword || !Gender) { | ||
toast.error("Ensure all fields are filled"); | ||
return false; | ||
} else if (ConfirmPassword != Password) { | ||
toast.error("Passwords don't match!!"); | ||
return false; | ||
} else if (Password.length < 6) { | ||
toast.error("Passwords must have atleast 6 characters"); | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
export default useSignup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.