Return error message if username is already taken during register

This will return an error message if the username is already registered. The user should choose another name
This commit is contained in:
cami 2021-06-30 00:03:34 +02:00
parent 3ab7ce0b5c
commit ea7be2283e
2 changed files with 13 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import "../../App.css";
import Footer from "../../Footer"; import Footer from "../../Footer";
import InputField from "../InputField"; import InputField from "../InputField";
import SubmitField from "../SubmitField"; import SubmitField from "../SubmitField";
import "../Input.css"
export default function Login() { export default function Login() {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
@ -21,15 +22,17 @@ export default function Login() {
method: "post", method: "post",
body: JSON.stringify(opts), body: JSON.stringify(opts),
}).then((response) => { }).then((response) => {
console.log(response)
if (response.status === 409) { if (response.status === 409) {
console.log(response); /*
console.log( then is needed twice to get rid of the javascript Promise thing
"Benutzername wird bereits verwendet. Wähle einen Anderen (source: console.log)" */
); response.json().then((resp2) => {
let response_json = response.json(); setMessage(resp2.message)
console.log(response_json); });
let response_message = response_json.message; }
console.log(response_message); else if (response.status === 200) {
//TODO redirect to login #77 or #74
} }
}); });
}; };
@ -53,6 +56,7 @@ export default function Login() {
onChange={handleUsernameChange} onChange={handleUsernameChange}
InputName="username" InputName="username"
/> />
<p>{message}</p>
<InputField <InputField
LabelName="Passwort" LabelName="Passwort"
InputType="password" InputType="password"