Skip to content

Commit

Permalink
add error message for same email
Browse files Browse the repository at this point in the history
  • Loading branch information
JamiCoder committed Dec 24, 2023
1 parent 553c306 commit 4019b25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
34 changes: 25 additions & 9 deletions frontend/src/pages/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { useRouter } from "next/router";
const auth = () => {
const [isRegistration, setIsRegistration] = useState(false);
const [isShowMessage, setIsShowMessage] = useState(false);
const [errorMessage, setErrorMessage] = useState('');

const router = useRouter();

async function onSubmit(event) {
event.preventDefault();
setErrorMessage('')

const formData = new FormData(event.currentTarget);

Expand Down Expand Up @@ -50,14 +53,17 @@ const auth = () => {

if (response) {
const data = await response.json();

console.log(data);
if (data.access_token) {
sessionStorage.setItem("accessToken", data.access_token);
router.push("/");
} else if (Array.isArray(data)) {
setIsShowMessage(true);
setIsRegistration(false);
if(!data.detail){
if (data.access_token) {
sessionStorage.setItem("accessToken", data.access_token);
router.push("/");
} else if (Array.isArray(data)) {
setIsShowMessage(true);
setIsRegistration(false);
}
}
else if (data.detail){
setErrorMessage(data.detail)
}
}
} catch (error) {
Expand All @@ -68,9 +74,11 @@ const auth = () => {
function showRegistration() {
setIsRegistration(!isRegistration);
}


return (
<div className="bg-white text-black min-h-screen flex flex-col justify-center py-12 px-6 lg:px-8">

<div className="sm:mx-auto sm:w-full sm:max-w-md text-center">
<img
src="./care-bot.png"
Expand All @@ -95,9 +103,14 @@ const auth = () => {
) : (
""
)}
{errorMessage && (
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
<p>{errorMessage}</p>
</div>
)}

<form className="space-y-6" onSubmit={onSubmit} method="POST">
{isRegistration ? <Registration /> : <Signin />}
{isRegistration ? <Registration/> : <Signin />}
</form>

<p className="mt-8 text-center text-sm text-gray-400">
Expand All @@ -115,6 +128,9 @@ const auth = () => {
};

const Registration = () => {



return (
<>
{/* Email field */}
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ validate-email-address==1
watchfiles==0.21.0
websockets==12.0
yarl==1.9.4
cohere
Binary file modified sql_app.db
Binary file not shown.

0 comments on commit 4019b25

Please sign in to comment.