Changeset b70fbeb
- Timestamp:
- 01/27/26 14:03:17 (6 months ago)
- Branches:
- main
- Children:
- 3238007
- Parents:
- 4e5cf92
- Files:
-
- 8 edited
-
finkwave/src/main/java/com/ukim/finki/develop/finkwave/model/RefreshToken.java (modified) (1 diff)
-
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/AuthService.java (modified) (6 diffs)
-
frontend/package-lock.json (modified) (3 diffs)
-
frontend/package.json (modified) (1 diff)
-
frontend/src/App.tsx (modified) (2 diffs)
-
frontend/src/pages/Login.tsx (modified) (2 diffs)
-
frontend/src/pages/Nav.tsx (modified) (2 diffs)
-
frontend/src/pages/Register.tsx (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
finkwave/src/main/java/com/ukim/finki/develop/finkwave/model/RefreshToken.java
r4e5cf92 rb70fbeb 9 9 @Entity 10 10 @Getter @Setter 11 @Table(name = "refresh_token") 11 12 public class RefreshToken { 12 13 @Id -
finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/AuthService.java
r4e5cf92 rb70fbeb 44 44 throws IOException { 45 45 if (userRepository.findByUsername(authRequestDto.username()).isPresent()){ 46 throw new RuntimeException(" User already exists");46 throw new RuntimeException("Error creating user."); 47 47 } 48 48 User user = createNonAdminUser(authRequestDto); … … 52 52 public UserResponseDto login(HttpServletResponse response, LoginRequestDto loginRequestDto){ 53 53 User user = userRepository.findByUsername(loginRequestDto.username()) 54 .orElseThrow(() -> new RuntimeException("Invalid credentials "));54 .orElseThrow(() -> new RuntimeException("Invalid credentials.")); 55 55 56 56 if (!passwordEncoder.matches(loginRequestDto.password(), user.getPassword())){ 57 throw new RuntimeException("Invalid credentials ");57 throw new RuntimeException("Invalid credentials."); 58 58 } 59 59 … … 74 74 public UserResponseDto getUserDtoByUsername(String username){ 75 75 User user = userRepository.findByUsername(username) 76 .orElseThrow(() -> new RuntimeException("Invalid credentials "));76 .orElseThrow(() -> new RuntimeException("Invalid credentials.")); 77 77 78 78 return userResponseFromUser(user); … … 103 103 Authentication authentication= SecurityContextHolder.getContext().getAuthentication(); 104 104 if (authentication == null || !authentication.isAuthenticated()) { 105 throw new RuntimeException("User not authenticated ");105 throw new RuntimeException("User not authenticated."); 106 106 } 107 107 … … 110 110 111 111 return userRepository.findByUsername(username).map(User::getId) 112 .orElseThrow(()->new RuntimeException("User not found "));112 .orElseThrow(()->new RuntimeException("User not found.")); 113 113 } 114 114 … … 126 126 if (profilePhoto != null) { 127 127 if (profilePhoto.getContentType() != null && !profilePhoto.getContentType().startsWith("image/")) 128 throw new IllegalArgumentException("Invalid fyle type ");128 throw new IllegalArgumentException("Invalid fyle type."); 129 129 130 if (profilePhoto.getSize() > 5_000_000) {130 if (profilePhoto.getSize() > 2_000_000) { 131 131 throw new IllegalArgumentException(("File too large.")); 132 132 } -
frontend/package-lock.json
r4e5cf92 rb70fbeb 15 15 "react-dom": "^19.2.0", 16 16 "react-router-dom": "^7.13.0", 17 "react-toastify": "^11.0.5", 17 18 "tailwindcss": "^4.1.18" 18 19 }, … … 2152 2153 "funding": { 2153 2154 "url": "https://github.com/chalk/chalk?sponsor=1" 2155 } 2156 }, 2157 "node_modules/clsx": { 2158 "version": "2.1.1", 2159 "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", 2160 "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", 2161 "license": "MIT", 2162 "engines": { 2163 "node": ">=6" 2154 2164 } 2155 2165 }, … … 3683 3693 } 3684 3694 }, 3695 "node_modules/react-toastify": { 3696 "version": "11.0.5", 3697 "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-11.0.5.tgz", 3698 "integrity": "sha512-EpqHBGvnSTtHYhCPLxML05NLY2ZX0JURbAdNYa6BUkk+amz4wbKBQvoKQAB0ardvSarUBuY4Q4s1sluAzZwkmA==", 3699 "license": "MIT", 3700 "dependencies": { 3701 "clsx": "^2.1.1" 3702 }, 3703 "peerDependencies": { 3704 "react": "^18 || ^19", 3705 "react-dom": "^18 || ^19" 3706 } 3707 }, 3685 3708 "node_modules/resolve-from": { 3686 3709 "version": "4.0.0", -
frontend/package.json
r4e5cf92 rb70fbeb 17 17 "react-dom": "^19.2.0", 18 18 "react-router-dom": "^7.13.0", 19 "react-toastify": "^11.0.5", 19 20 "tailwindcss": "^4.1.18" 20 21 }, -
frontend/src/App.tsx
r4e5cf92 rb70fbeb 1 1 import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom"; 2 import { ToastContainer } from "react-toastify"; 3 import "react-toastify/dist/ReactToastify.css"; 2 4 import AllUsers from "./pages/AllUsers"; 3 5 import LandingPage from "./pages/LandingPage"; … … 11 13 <div className="flex flex-col min-h-screen"> 12 14 <Nav /> 15 <ToastContainer 16 position="top-right" 17 autoClose={2000} 18 hideProgressBar={false} 19 newestOnTop={false} 20 closeOnClick 21 rtl={false} 22 pauseOnFocusLoss 23 draggable 24 pauseOnHover 25 theme="light" 26 /> 13 27 <main className="grow"> 14 28 <Outlet /> -
frontend/src/pages/Login.tsx
r4e5cf92 rb70fbeb 1 1 import { useState } from "react"; 2 2 import { useNavigate } from "react-router-dom"; 3 import { toast } from "react-toastify"; 3 4 import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance"; 4 5 import { useAuth } from "../context/authContext"; … … 22 23 setUser(response.data.user); 23 24 navigate("/"); 24 } catch (error) { 25 setError("Login failed. Please check your credentials."); 25 toast.success("Login successful!"); 26 } catch (error: any) { 27 const errorMessage = 28 error.response?.data?.error || 29 "Login failed. Please check your credentials."; 30 setError(errorMessage); 31 toast.error(errorMessage); 26 32 } 27 33 }; -
frontend/src/pages/Nav.tsx
r4e5cf92 rb70fbeb 1 1 import { Link } from "react-router-dom"; 2 import { toast } from "react-toastify"; 2 3 import axiosInstance, { baseURL } from "../api/axiosInstance"; 3 4 import Logo from "../assets/logo-finkwave.png"; … … 12 13 await axiosInstance.post("/auth/logout"); 13 14 setUser(undefined); 15 toast.success("Logout successful!"); 14 16 } catch (error) { 15 17 console.error("Logout failed:", error); 18 toast.error("Logout failed!"); 16 19 } 17 20 }; -
frontend/src/pages/Register.tsx
r4e5cf92 rb70fbeb 1 1 import { useEffect, useState } from "react"; 2 2 import { useNavigate } from "react-router"; 3 import { toast } from "react-toastify"; 3 4 import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance"; 4 5 import { useAuth } from "../context/authContext"; … … 15 16 null, 16 17 ); 18 const [error, setError] = useState<string | null>(null); 17 19 18 20 const navigate = useNavigate(); … … 28 30 const handleRegister = async (e: React.FormEvent) => { 29 31 e.preventDefault(); 30 // todo: add proper error handling31 32 if (profilePhotoFile && profilePhotoFile.size > 5 * 1024 * 1024) { 32 33 alert("Max file size is 5MB"); … … 53 54 setUser(response.data.user); 54 55 navigate("/"); 55 } catch (error) { 56 console.error("Registration failed:", error); 56 toast.success("Registration successful!"); 57 } catch (error: any) { 58 const errorMessage = 59 error.response?.data?.error || "Registration failed. Please try again."; 60 setError(errorMessage); 61 toast.error(errorMessage); 57 62 } 58 63 }; … … 62 67 <h2 className="text-2xl mb-4">Register</h2> 63 68 <form className="bg-white p-6 rounded shadow-md w-80"> 69 {error && <p className="text-red-500 mb-4">{error}</p>} 64 70 <div className="mb-4"> 65 71 <label className="block text-gray-700 mb-2" htmlFor="username">
Note:
See TracChangeset
for help on using the changeset viewer.
