From 18f76d8cd657fa9f5186ed622e286ffddd331080 Mon Sep 17 00:00:00 2001 From: cami Date: Tue, 6 Jul 2021 02:12:32 +0200 Subject: [PATCH] After the registration user will be logged in and redirected to survey (fix #77 and fix #74) --- frontend/src/components/pages/Login.js | 2 +- frontend/src/components/pages/Register.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/pages/Login.js b/frontend/src/components/pages/Login.js index cd399ee..69b3021 100644 --- a/frontend/src/components/pages/Login.js +++ b/frontend/src/components/pages/Login.js @@ -66,7 +66,7 @@ export default function Login() { InputPlaceHolder="Passwort" />
- + ) : ( diff --git a/frontend/src/components/pages/Register.js b/frontend/src/components/pages/Register.js index 5d6f241..11308f4 100644 --- a/frontend/src/components/pages/Register.js +++ b/frontend/src/components/pages/Register.js @@ -6,6 +6,8 @@ import InputField from "../InputField"; import SubmitField from "../SubmitField"; import "../Input.css"; import ErrorMessage from "../ErrorMessage"; +import { login, useAuth } from "../../auth/AuthProvider"; +import { Redirect } from "react-router-dom"; export default function Login() { const [username, setUsername] = useState(""); @@ -16,6 +18,8 @@ export default function Login() { const [isStatusOk, setIsStatusOk] = useState(""); + const [isLoggedIn] = useAuth(); + const onSubmitClick = (e) => { e.preventDefault(); let opts = { @@ -37,6 +41,14 @@ export default function Login() { } else if (response.status === 200) { response.json().then((resp) => { setMessage(resp.message); + fetch("/api/login", { + method: "post", + body: JSON.stringify(opts), + }).then((response) => { + response.json().then((token) => { + login(token); + }); + }); }); setIsStatusOk(true); } @@ -73,7 +85,7 @@ export default function Login() { - {isStatusOk &&

{message}

} + {isLoggedIn && }