* {meta.error}
)} )} @@ -118,7 +118,7 @@ export const PasswordField = ({ )} {meta.touched && meta.error && ( -* {meta.error}
)} )} diff --git a/web/src/screens/auth/login.tsx b/web/src/screens/auth/login.tsx index fc40d4b..d97eb43 100644 --- a/web/src/screens/auth/login.tsx +++ b/web/src/screens/auth/login.tsx @@ -7,68 +7,72 @@ import { TextField, PasswordField } from "../../components/inputs"; import logo from "../../logo.png"; import { AuthContext } from "../../utils/Context"; +import { useEffect } from "react"; interface LoginData { - username: string; - password: string; + username: string; + password: string; } -function Login() { - const history = useHistory(); - const [, setAuthContext] = AuthContext.use(); +export const Login = () => { + const history = useHistory(); + const [, setAuthContext] = AuthContext.use(); - const mutation = useMutation( - (data: LoginData) => APIClient.auth.login(data.username, data.password), - { - onSuccess: (_, variables: LoginData) => { - setAuthContext({ - username: variables.username, - isLoggedIn: true - }); - history.push("/"); - }, - } - ); + useEffect(() => { + // Check if onboarding is available for this instance + // and redirect if needed + APIClient.auth.canOnboard() + .then(() => history.push("/onboard")); + }, [history]); - const handleSubmit = (data: any) => mutation.mutate(data); + const mutation = useMutation( + (data: LoginData) => APIClient.auth.login(data.username, data.password), + { + onSuccess: (_, variables: LoginData) => { + setAuthContext({ + username: variables.username, + isLoggedIn: true + }); + history.push("/"); + }, + } + ); - return ( -Logged out
-Logged out
+