diff --git a/components/AuthProfileMenu.tsx b/components/AuthProfileMenu.tsx index 02a3b2a3..1c563609 100644 --- a/components/AuthProfileMenu.tsx +++ b/components/AuthProfileMenu.tsx @@ -15,6 +15,15 @@ import React, { Fragment } from "react"; export default function AuthProfileMenu() { const [anchorEl, setAnchorEl] = React.useState(null); + const [userRole, setUserRole] = React.useState(""); + const token = localStorage.getItem("token"); + React.useEffect(() => { + if (token) { + const role = JSON.parse(atob(token.split(".")[1])).role; + setUserRole(role); + } + }, [token, userRole]); + const open = Boolean(anchorEl); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); @@ -25,6 +34,16 @@ export default function AuthProfileMenu() { const router = useRouter(); + const handleMyAccount = () => { + if (userRole == "admin") { + router.push("/admin-page") + } else if (userRole == "creator") { + router.push("/creator-page") + } else { + router.push("/profile") + } + }; + const handleLogOut = () => { localStorage.removeItem("token"); window.location.reload(); @@ -81,11 +100,8 @@ export default function AuthProfileMenu() { transformOrigin={{ horizontal: "right", vertical: "top" }} anchorOrigin={{ horizontal: "right", vertical: "bottom" }} > - - Profile - - - My account + + My Account