This commit is contained in:
parent
942c22c515
commit
18f76d8cd6
2 changed files with 14 additions and 2 deletions
|
@ -66,7 +66,7 @@ export default function Login() {
|
||||||
InputPlaceHolder="Passwort"
|
InputPlaceHolder="Passwort"
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<ErrorMessage message={errorMessage}/>
|
<ErrorMessage message={errorMessage} />
|
||||||
<SubmitField onClick={onSubmitClick} LabelName="Einloggen" />
|
<SubmitField onClick={onSubmitClick} LabelName="Einloggen" />
|
||||||
</form>
|
</form>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -6,6 +6,8 @@ import InputField from "../InputField";
|
||||||
import SubmitField from "../SubmitField";
|
import SubmitField from "../SubmitField";
|
||||||
import "../Input.css";
|
import "../Input.css";
|
||||||
import ErrorMessage from "../ErrorMessage";
|
import ErrorMessage from "../ErrorMessage";
|
||||||
|
import { login, useAuth } from "../../auth/AuthProvider";
|
||||||
|
import { Redirect } from "react-router-dom";
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const [username, setUsername] = useState("");
|
const [username, setUsername] = useState("");
|
||||||
|
@ -16,6 +18,8 @@ export default function Login() {
|
||||||
|
|
||||||
const [isStatusOk, setIsStatusOk] = useState("");
|
const [isStatusOk, setIsStatusOk] = useState("");
|
||||||
|
|
||||||
|
const [isLoggedIn] = useAuth();
|
||||||
|
|
||||||
const onSubmitClick = (e) => {
|
const onSubmitClick = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let opts = {
|
let opts = {
|
||||||
|
@ -37,6 +41,14 @@ export default function Login() {
|
||||||
} else if (response.status === 200) {
|
} else if (response.status === 200) {
|
||||||
response.json().then((resp) => {
|
response.json().then((resp) => {
|
||||||
setMessage(resp.message);
|
setMessage(resp.message);
|
||||||
|
fetch("/api/login", {
|
||||||
|
method: "post",
|
||||||
|
body: JSON.stringify(opts),
|
||||||
|
}).then((response) => {
|
||||||
|
response.json().then((token) => {
|
||||||
|
login(token);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
setIsStatusOk(true);
|
setIsStatusOk(true);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +85,7 @@ export default function Login() {
|
||||||
<SubmitField onClick={onSubmitClick} LabelName="Registrieren" />
|
<SubmitField onClick={onSubmitClick} LabelName="Registrieren" />
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{isStatusOk && <p>{message}</p>}
|
{isLoggedIn && <Redirect to="/umfrage" />}
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue