Fixed isAdmin code in navbar and login
This commit is contained in:
@@ -15,10 +15,6 @@ function AuthPage() {
|
||||
});
|
||||
const [signin, setSignin] = useState(false);
|
||||
|
||||
const adminEmails = [
|
||||
"harshitha.ss@somaiya.edu",
|
||||
];
|
||||
|
||||
const notifyError = (message) => {
|
||||
toast.error(message);
|
||||
};
|
||||
@@ -74,17 +70,8 @@ function AuthPage() {
|
||||
)}?d=identicon`;
|
||||
user.profilePicture = gravatarUrl;
|
||||
|
||||
if (adminEmails.includes(user.email)) {
|
||||
await axios.post(`http://localhost:8080/api/user/make-admin/${user._id}`);
|
||||
const updatedUser = await axios.get(`http://localhost:8080/api/user/${user._id}`);
|
||||
user.isAdmin = updatedUser.data.isAdmin;
|
||||
localStorage.setItem("isAdmin", user.isAdmin);
|
||||
} else {
|
||||
localStorage.setItem("isAdmin", false);
|
||||
}
|
||||
|
||||
// ✅ Save user to localStorage
|
||||
localStorage.setItem("user", JSON.stringify(user));
|
||||
|
||||
window.location.href = "/Welcome";
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -98,20 +85,6 @@ function AuthPage() {
|
||||
window.location.href = "http://localhost:8080/auth/google";
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const queryParams = new URLSearchParams(window.location.search);
|
||||
const email = queryParams.get("email");
|
||||
|
||||
if (email) {
|
||||
if (adminEmails.includes(email)) {
|
||||
localStorage.setItem("isAdmin", true);
|
||||
} else {
|
||||
localStorage.setItem("isAdmin", false);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<ToastContainer />
|
||||
@@ -265,4 +238,4 @@ function SignInForm(props) {
|
||||
);
|
||||
}
|
||||
|
||||
export default AuthPage;
|
||||
export default AuthPage;
|
||||
Reference in New Issue
Block a user