Skip to content

Commit 106f8eb

Browse files
committed
Fixed the security vulnerbility where HMAC key was visible
1 parent a06dc57 commit 106f8eb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/pages/dashboard.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { useRouter } from "next/router";
66
import { ToastContainer, toast } from "react-toastify";
77
import "react-toastify/dist/ReactToastify.css";
88
import LoadingSpinner from "./components/LoadingSpinner";
9-
import generateToken from "../utils/generateToken";
109
import { FaSun, FaMoon, FaSignOutAlt } from "react-icons/fa";
1110

1211
const Dashboard = () => {
@@ -127,10 +126,13 @@ const Dashboard = () => {
127126
throw new Error("Access token not found.");
128127
}
129128

130-
const newToken = generateToken(user.id, process.env.HMAC_KEY);
129+
const response = await axios.post("/api/auth/generate-random-token", {
130+
id: user.id,
131+
});
131132

132-
// Send the new token to the server to save it, similar to the original logic
133-
const response = await axios.post("/api/auth/user", {
133+
const newToken = response.data.token;
134+
// Send the new token to the server to save it, similar to the original logic
135+
await axios.post("/api/auth/user", {
134136
id: user.id,
135137
token: newToken,
136138
});
@@ -144,8 +146,6 @@ const Dashboard = () => {
144146
toast.info("Successfully regenerated!", {
145147
position: toast.POSITION.BOTTOM_RIGHT,
146148
});
147-
148-
console.log(response.data);
149149
} catch (error) {
150150
if (error.message.startsWith("Rate limit exceeded")) {
151151
toast.error(error.message, {

0 commit comments

Comments
 (0)