Skip to content

Commit e863d15

Browse files
committed
Add error notifications for failed sign up or log in
1 parent efd5c39 commit e863d15

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

backend/user-service/controller/user-controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function createUser(
3131
if (existingUser) {
3232
return res
3333
.status(409)
34-
.json({ message: "username or email already exists" });
34+
.json({ message: "Username or email already exists" });
3535
}
3636

3737
// TODO: validate first and last name
@@ -70,7 +70,7 @@ export async function createUser(
7070
} else {
7171
return res.status(400).json({
7272
message:
73-
"at least one of first name, last name, username, email and password are missing",
73+
"At least one of first name, last name, username, email and password are missing",
7474
});
7575
}
7676
} catch (err) {

frontend/src/contexts/AuthContext.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createContext, useContext, useEffect, useState } from "react";
44
import { userClient } from "../utils/api";
55
import { useNavigate } from "react-router-dom";
66
import { Box } from "@mui/material";
7+
import { toast } from "react-toastify";
78

89
type User = {
910
id: string;
@@ -69,7 +70,10 @@ const AuthProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
6970
password: password,
7071
})
7172
.then(() => login(email, password))
72-
.catch(() => setUser(null));
73+
.catch((err) => {
74+
setUser(null);
75+
toast.error(err.response.data.message);
76+
});
7377
};
7478

7579
const login = (email: string, password: string) => {
@@ -84,7 +88,10 @@ const AuthProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
8488
setUser(user);
8589
navigate("/");
8690
})
87-
.catch(() => setUser(null));
91+
.catch((err) => {
92+
setUser(null);
93+
toast.error(err.response.data.message);
94+
});
8895
};
8996

9097
const logout = () => {

frontend/src/pages/LogIn/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useNavigate } from "react-router-dom";
55
import { useAuth } from "../../contexts/AuthContext";
66
import CustomTextField from "../../components/CustomTextField";
77
import { emailValidator } from "../../utils/validators";
8+
import { ToastContainer } from "react-toastify";
89

910
const LogIn: React.FC = () => {
1011
const navigate = useNavigate();
@@ -140,6 +141,7 @@ const LogIn: React.FC = () => {
140141
>
141142
<LogInSvg width="80%" height="80%" />
142143
</Box>
144+
<ToastContainer position="bottom-right" />
143145
</Box>
144146
);
145147
};

frontend/src/pages/SignUp/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useAuth } from "../../contexts/AuthContext";
55
import CustomTextField from "../../components/CustomTextField";
66
import { emailValidator, nameValidator, passwordValidator, usernameValidator } from "../../utils/validators";
77
import { useRef, useState } from "react";
8+
import { ToastContainer } from "react-toastify";
89

910
const SignUp: React.FC = () => {
1011
const navigate = useNavigate();
@@ -168,6 +169,7 @@ const SignUp: React.FC = () => {
168169
>
169170
<SignUpSvg width="80%" height="80%" />
170171
</Box>
172+
<ToastContainer position="bottom-right" />
171173
</Box>
172174
);
173175
};

0 commit comments

Comments
 (0)