Skip to content

Commit 47d849b

Browse files
committed
only POST methode allowed form delete , insert login updatepage and updatelink routes . minor tidy up in alert
1 parent 6031578 commit 47d849b

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

components/alert.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import { useEffect, useState } from "react";
1+
// import { useEffect, useState } from "react";
22

33
export default function Alert({ msg, type = "danger" }) {
4-
const [msgstate, setmsg] = useState(msg);
4+
// const [msgstate, setmsg] = useState(msg);
55

6-
useEffect(() => {
7-
// return;
8-
}, [msg]);
9-
console.log("alert ", msg, type);
6+
// console.log("alert ", msg, type);
107
return (
118
<div className="mt-4">
12-
<div hidden={!msgstate} className={`text-center alert alert-${type}`}>
13-
{msgstate}
9+
<div hidden={!msg} className={`text-center alert alert-${type}`}>
10+
{msg}
1411
</div>
1512
</div>
1613
);

pages/api/deletepagelink.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { jwtAuth, use } from "../../middleware/middleware";
22
import { deleteLink, getLinkData } from "../../lib/dbfunc";
33

44
async function handler(req, res) {
5+
if (req.method !== "POST") {
6+
res.status(400).send("method not allowed");
7+
return;
8+
}
59
try {
610
// Run the middleware
711
await use(req, res, jwtAuth);

pages/api/insertpagelinks.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import { jwtAuth, use } from "../../middleware/middleware";
22
import { getLinkData, insertPageLinks } from "../../lib/dbfunc";
33

44
async function handler(req, res) {
5-
5+
if (req.method !== "POST") {
6+
res.status(400).send("method not allowed");
7+
return;
8+
}
69
try {
7-
// Run the middleware
10+
// Run the middleware
811
await use(req, res, jwtAuth);
912
// console.log(req.body);
1013

1114
await insertPageLinks(req.body);
12-
15+
1316
let updatedLinkData = await getLinkData();
1417
// console.log(updatedPageData);
1518
res.json({ success: true, updatedLinkData: updatedLinkData.linkData });

pages/api/login.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export default async function handler(req, res) {
3232
}
3333

3434
let token = createSecureToken({ username: data.username });
35-
console.log(data);
36-
console.log(token);
37-
console.log(pass);
35+
// console.log(data);
36+
// console.log(token);
37+
// console.log(pass);
3838

3939
const cookie = serialize("linkin.auth", token, {
4040
path: "/",
@@ -43,7 +43,7 @@ export default async function handler(req, res) {
4343
maxAge: 60 * 60 * 24 * 365,
4444
});
4545

46-
console.log(cookie);
46+
// console.log(cookie);
4747

4848
res.setHeader("Set-Cookie", [cookie]);
4949

pages/api/updatepagedata.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import { jwtAuth, use } from "../../middleware/middleware";
22
import { updatePageData, getPageData } from "../../lib/dbfunc";
33

44
async function handler(req, res) {
5+
if (req.method !== "POST") {
6+
res.status(400).send("method not allowed");
7+
return;
8+
}
59
try {
610
// Run the middleware
7-
811
await use(req, res, jwtAuth);
912
// console.log(req.body);
1013

pages/api/updatepagelinks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { jwtAuth, use } from "../../middleware/middleware";
22
import { getLinkData, updateLink } from "../../lib/dbfunc";
33

44
async function handler(req, res) {
5+
if (req.method !== "POST") {
6+
res.status(400).send("method not allowed");
7+
return;
8+
}
59
try {
610
// Run the middleware
711
await use(req, res, jwtAuth);

0 commit comments

Comments
 (0)