Skip to content

Commit

Permalink
Merge pull request #1866 from bcgov/chore/fetch-csrf-cookie
Browse files Browse the repository at this point in the history
chore: add function to fetch specific csrf cookie by name
  • Loading branch information
BCerki authored Sep 15, 2023
2 parents b0ea1bc + 9a4796a commit 25a8eac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/components/Attachment/hardDeleteAttachment.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { getAttachmentDeleteRoute } from "routes/pageRoutes";

const getCookie = (name) => {
const match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)"));
if (match) {
return match[2];
} else {
console.log(`No cookie matching ${name} was found`);
}
};

const hardDeleteAttachment = async (attachmentId, formChangeRowId) => {
const csrfToken = document.cookie.replace("qwerty=", "");
const csrfToken = getCookie("luscaCSRF");
fetch(getAttachmentDeleteRoute(attachmentId).pathname, {
method: "DELETE",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion app/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ app.prepare().then(async () => {
lusca.csrf({
xframe: "SAMEORIGIN",
xssProtection: true,
cookie: "qwerty",
cookie: "luscaCSRF",
})
);
server.use(attachmentDeleteRouter);
Expand Down

0 comments on commit 25a8eac

Please sign in to comment.