Skip to content

Commit

Permalink
Add unauthorized sign-in toast
Browse files Browse the repository at this point in the history
  • Loading branch information
ahkim3 committed Dec 8, 2023
1 parent 9ef8e37 commit 0569b2c
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
110 changes: 110 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react-router-dom": "^6.20.1",
"react-scripts": "5.0.1",
"react-select": "^5.8.0",
"react-toastify": "^9.1.3",
"reactjs-popup": "^2.0.6",
"web-vitals": "^2.1.4"
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Route,
Navigate,
} from "react-router-dom";
import {ToastContainer} from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import axios from "axios";
import SignIn from "./SignIn";
import SignOut from "./SignOut";
Expand Down Expand Up @@ -64,6 +66,7 @@ const App = () => {

return (
<Router>
<ToastContainer />
<Routes>
<Route
path="/pages/EPackMenu"
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from "react";
import axios from "axios";
import {GoogleLogin} from "@react-oauth/google";
import {jwtDecode} from "jwt-decode";
import {toast, ToastContainer} from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import "./SignIn.css";
import logo from "./welcomeLogo.svg";

Expand Down Expand Up @@ -34,6 +36,16 @@ const SignIn = ({setUser}) => {
window.location.href = "/pages/PantryMenu";
})
.catch((error) => {
// Check if response.status is 400 and if response.data is "Invalid permission level"
if (
error.response.status === 400 &&
error.response.data === "Invalid permission level"
) {
// Show a toast notification to the user
toast.error(
"You don't have the required permissions to login."
);
}
console.error("Error:", error);
});
};
Expand Down

0 comments on commit 0569b2c

Please sign in to comment.