Password
@@ -68,12 +67,11 @@ export const Login = () => {
autoComplete="current-password"
required
id="id_password" />
- {isError &&
-
-
Password or Username is wrong
-
- }
-
+ { isError && axios.isAxiosError(error) &&
+
+
{error?.response?.data.message || "Password or Username is wrong"}
+
+ }
@@ -82,6 +80,5 @@ export const Login = () => {
Register
}
>
-
);
};
\ No newline at end of file
diff --git a/src/main/client/src/routes/Register/Register.tsx b/src/main/client/src/routes/Register/Register.tsx
new file mode 100644
index 0000000..03dda27
--- /dev/null
+++ b/src/main/client/src/routes/Register/Register.tsx
@@ -0,0 +1,142 @@
+import { Link, useNavigate } from "react-router-dom";
+import "../../components/styling/auth.css";
+import { useRef } from "react";
+import { useErgonClient } from "../../hooks/useErgonClient/useErgonClient.tsx";
+import { useMutation } from "@tanstack/react-query";
+import Loading from "../../components/Loader";
+import axios from "axios";
+
+export const Register = () => {
+ const username = useRef
(null);
+ const password = useRef(null);
+ const confirmPassword = useRef(null);
+ const email = useRef(null);
+ const firstName = useRef(null);
+ const lastName = useRef(null);
+ const dob = useRef(null);
+ const client = useErgonClient();
+ const navigate = useNavigate();
+
+ const registerUser = async () => {
+ const user = username.current?.value;
+ const pass = password.current?.value;
+ const confirmPass = confirmPassword.current?.value;
+ const userEmail = email.current?.value;
+ const fName = firstName.current?.value;
+ const lName = lastName.current?.value;
+ const dateOfBirth = dob.current?.value;
+
+ if (pass !== confirmPass) {
+ throw new Error("Passwords do not match");
+ }
+
+ return await client.post("/auth/registration", {
+ username: user,
+ password: pass,
+ matchingPassword: confirmPass,
+ email: userEmail,
+ firstName: fName,
+ lastName: lName,
+ dob: dateOfBirth
+ });
+ };
+
+ const { mutate, isError, isPending, error } = useMutation({
+ mutationFn: registerUser,
+ onSuccess: () => {
+ navigate("/login");
+ }
+ });
+
+ const handleRegister = () => {
+ mutate();
+ };
+
+ return (
+ <>
+
+ {isPending ?
:
+
+
Register
+
+
+
+
+
+
+ { isError && axios.isAxiosError(error) &&
+
+
{error?.response?.data.message || "Registration failed, and its not my code, its you with your weird input"}
+
+ }
+
+
+
+
Login
+
}
+ >
+ );
+};
\ No newline at end of file
diff --git a/src/main/java/com/tibs/Ergon/controller/AuthController.java b/src/main/java/com/tibs/Ergon/controller/AuthController.java
index dffc392..619faac 100644
--- a/src/main/java/com/tibs/Ergon/controller/AuthController.java
+++ b/src/main/java/com/tibs/Ergon/controller/AuthController.java
@@ -39,7 +39,7 @@ public AuthController(AuthenticationManager authenticationManager, JwtUtil jwtUt
@PostMapping("/login")
public ResponseEntity> createAuthenticationToken(@RequestBody AuthRequest authRequest) {
try {
- log.info("Attempting to authenticate user: %s" + authRequest.getUsername());
+ log.info("Attempting to authenticate user: " + authRequest.getUsername());
authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(authRequest.getUsername(), authRequest.getPassword())
);