Changeset b70fbeb


Ignore:
Timestamp:
01/27/26 14:03:17 (6 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
3238007
Parents:
4e5cf92
Message:

add toasts on frontend

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/model/RefreshToken.java

    r4e5cf92 rb70fbeb  
    99@Entity
    1010@Getter @Setter
     11@Table(name = "refresh_token")
    1112public class RefreshToken {
    1213    @Id
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/AuthService.java

    r4e5cf92 rb70fbeb  
    4444    throws IOException {
    4545        if (userRepository.findByUsername(authRequestDto.username()).isPresent()){
    46             throw new RuntimeException("User already exists");
     46            throw new RuntimeException("Error creating user.");
    4747        }
    4848        User user = createNonAdminUser(authRequestDto);
     
    5252    public UserResponseDto login(HttpServletResponse response, LoginRequestDto loginRequestDto){
    5353        User user = userRepository.findByUsername(loginRequestDto.username())
    54                 .orElseThrow(() -> new RuntimeException("Invalid credentials"));
     54                .orElseThrow(() -> new RuntimeException("Invalid credentials."));
    5555
    5656        if (!passwordEncoder.matches(loginRequestDto.password(), user.getPassword())){
    57             throw new RuntimeException("Invalid credentials");
     57            throw new RuntimeException("Invalid credentials.");
    5858        }
    5959
     
    7474    public UserResponseDto getUserDtoByUsername(String username){
    7575        User user = userRepository.findByUsername(username)
    76                 .orElseThrow(() -> new RuntimeException("Invalid credentials"));
     76                .orElseThrow(() -> new RuntimeException("Invalid credentials."));
    7777
    7878        return userResponseFromUser(user);
     
    103103        Authentication authentication= SecurityContextHolder.getContext().getAuthentication();
    104104        if (authentication == null || !authentication.isAuthenticated()) {
    105             throw new RuntimeException("User not authenticated");
     105            throw new RuntimeException("User not authenticated.");
    106106        }
    107107
     
    110110
    111111        return userRepository.findByUsername(username).map(User::getId)
    112                 .orElseThrow(()->new RuntimeException("User not found"));
     112                .orElseThrow(()->new RuntimeException("User not found."));
    113113    }
    114114
     
    126126        if (profilePhoto != null) {
    127127            if (profilePhoto.getContentType() != null && !profilePhoto.getContentType().startsWith("image/"))
    128                 throw new IllegalArgumentException("Invalid fyle type");
     128                throw new IllegalArgumentException("Invalid fyle type.");
    129129
    130             if (profilePhoto.getSize() > 5_000_000) {
     130            if (profilePhoto.getSize() > 2_000_000) {
    131131                throw new IllegalArgumentException(("File too large."));
    132132            }
  • frontend/package-lock.json

    r4e5cf92 rb70fbeb  
    1515                                "react-dom": "^19.2.0",
    1616                                "react-router-dom": "^7.13.0",
     17                                "react-toastify": "^11.0.5",
    1718                                "tailwindcss": "^4.1.18"
    1819                        },
     
    21522153                        "funding": {
    21532154                                "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"
    21542164                        }
    21552165                },
     
    36833693                        }
    36843694                },
     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                },
    36853708                "node_modules/resolve-from": {
    36863709                        "version": "4.0.0",
  • frontend/package.json

    r4e5cf92 rb70fbeb  
    1717                "react-dom": "^19.2.0",
    1818                "react-router-dom": "^7.13.0",
     19                "react-toastify": "^11.0.5",
    1920                "tailwindcss": "^4.1.18"
    2021        },
  • frontend/src/App.tsx

    r4e5cf92 rb70fbeb  
    11import { createBrowserRouter, Outlet, RouterProvider } from "react-router-dom";
     2import { ToastContainer } from "react-toastify";
     3import "react-toastify/dist/ReactToastify.css";
    24import AllUsers from "./pages/AllUsers";
    35import LandingPage from "./pages/LandingPage";
     
    1113                <div className="flex flex-col min-h-screen">
    1214                        <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                        />
    1327                        <main className="grow">
    1428                                <Outlet />
  • frontend/src/pages/Login.tsx

    r4e5cf92 rb70fbeb  
    11import { useState } from "react";
    22import { useNavigate } from "react-router-dom";
     3import { toast } from "react-toastify";
    34import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance";
    45import { useAuth } from "../context/authContext";
     
    2223                        setUser(response.data.user);
    2324                        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);
    2632                }
    2733        };
  • frontend/src/pages/Nav.tsx

    r4e5cf92 rb70fbeb  
    11import { Link } from "react-router-dom";
     2import { toast } from "react-toastify";
    23import axiosInstance, { baseURL } from "../api/axiosInstance";
    34import Logo from "../assets/logo-finkwave.png";
     
    1213                        await axiosInstance.post("/auth/logout");
    1314                        setUser(undefined);
     15                        toast.success("Logout successful!");
    1416                } catch (error) {
    1517                        console.error("Logout failed:", error);
     18                        toast.error("Logout failed!");
    1619                }
    1720        };
  • frontend/src/pages/Register.tsx

    r4e5cf92 rb70fbeb  
    11import { useEffect, useState } from "react";
    22import { useNavigate } from "react-router";
     3import { toast } from "react-toastify";
    34import axiosInstance, { scheduleTokenRefresh } from "../api/axiosInstance";
    45import { useAuth } from "../context/authContext";
     
    1516                null,
    1617        );
     18        const [error, setError] = useState<string | null>(null);
    1719
    1820        const navigate = useNavigate();
     
    2830        const handleRegister = async (e: React.FormEvent) => {
    2931                e.preventDefault();
    30                 // todo: add proper error handling
    3132                if (profilePhotoFile && profilePhotoFile.size > 5 * 1024 * 1024) {
    3233                        alert("Max file size is 5MB");
     
    5354                        setUser(response.data.user);
    5455                        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);
    5762                }
    5863        };
     
    6267                        <h2 className="text-2xl mb-4">Register</h2>
    6368                        <form className="bg-white p-6 rounded shadow-md w-80">
     69                                {error && <p className="text-red-500 mb-4">{error}</p>}
    6470                                <div className="mb-4">
    6571                                        <label className="block text-gray-700 mb-2" htmlFor="username">
Note: See TracChangeset for help on using the changeset viewer.