Implement 🥚

This commit is contained in:
grimsi
2024-09-27 11:04:13 +02:00
parent e47ab8405f
commit c8eaf0fb54
4 changed files with 102 additions and 23 deletions
+4 -8
View File
@@ -18,22 +18,18 @@ export default function LoginView() {
const [url, setUrl] = useState<string>();
const [signUpAllowed, setSignUpAllowed] = useState<boolean>(false);
useEffect(() => {
RegistrationEndpoint.isSelfRegistrationAllowed().then(setSignUpAllowed);
}, []);
useEffect(() => {
if (state.user) {
const path = url ? new URL(url, document.baseURI).pathname : '/'
navigate(path, {replace: true});
} else {
RegistrationEndpoint.isSelfRegistrationAllowed().then(setSignUpAllowed);
}
}, [state.user]);
async function tryLogin(values: any, formik: any) {
const {defaultUrl, error, redirectUrl} = await login(values.username, values.password);
if (!error) {
setUrl(redirectUrl ?? defaultUrl ?? '/');
} else {
const {error} = await login(values.username, values.password);
if (error) {
formik.setFieldError("username", " "); // Mark the field red, but don't show an error message
formik.setFieldError("password", "Invalid username and/or password.");
}