Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BCerki committed Sep 8, 2023
1 parent af26705 commit 23fb3a8
Show file tree
Hide file tree
Showing 9 changed files with 2 additions and 179 deletions.
1 change: 0 additions & 1 deletion app/components/Attachment/AttachmentTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const AttachmentTableRow: React.FC<Props> = ({

const handleArchiveAttachment = (attachmentId) => {
if (isFirstRevision) {
// hardDeleteAttachment(attachmentId, formChangeRowId, csrfToken);
hardDeleteAttachment(attachmentId, formChangeRowId);
router.replace(router.asPath);
} else {
Expand Down
6 changes: 0 additions & 6 deletions app/components/Attachment/hardDeleteAttachment.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { getAttachmentDeleteRoute } from "routes/pageRoutes";

const hardDeleteAttachment = async (attachmentId, formChangeRowId) => {
// const brianna = await fetch("/");
// console.log("document", document.cookie);
const csrfToken = document.cookie.replace("qwerty=", "");
console.log("csrfToken", decodeURIComponent(csrfToken));
// console.log("document.cookiedecoded", decodeURI(document.cookie));
fetch(getAttachmentDeleteRoute(attachmentId).pathname, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": decodeURIComponent(csrfToken),
_csrf: decodeURIComponent(csrfToken),
},
// headers: { "Content-Type": "application/json" },
body: JSON.stringify({
variables: {
input: {
Expand Down
14 changes: 0 additions & 14 deletions app/lib/relay/server.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import { get as getCookie } from "react-cookie";
import { Network, Environment, Store, RecordSource } from "relay-runtime";
import getConfig from "next/config";

const {
serverRuntimeConfig: { PORT },
publicRuntimeConfig: { SESSION_SECRET },
} = getConfig();

export function createServerNetwork({ cookieHeader }) {
console.log("--------------------");
console.log("$$$$$$$$cookieHeader", cookieHeader);
// console.log("getCookie", getCookie("qwerty"));
// console.log("getConfig()", getConfig());
console.log("spliting", cookieHeader.split("; ")[1].replace("qwerty=", ""));
console.log("--------------------");
// console.log("SESSION_SECRET", SESSION_SECRET);
return Network.create(async (params, variables) => {
const response = await fetch(`http://localhost:${PORT}/graphql`, {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
cookie: cookieHeader,
qwerty: cookieHeader.split("; ")[1].replace("qwerty=", ""),
"CSRF-TOKEN": cookieHeader.split("; ")[1].replace("qwerty=", ""),
// "CSRF-TOKEN": "_csrf",
// "CSRF-TOKEN": cookieHeader.split("; ")[1].replace("CSRF-TOKEN=", ""),
// "x-csrf-token": SESSION_SECRET,
},
body: JSON.stringify({
query: params.text,
Expand Down
2 changes: 0 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"ajv": "^8.9.0",
"body-parser": "^1.20.0",
"bowser": "^2.11.0",
"browser-cookies": "^1.2.0",
"connect-pg-simple": "^7.0.0",
"convict": "^6.2.4",
"convict-format-with-validator": "^6.2.0",
Expand Down Expand Up @@ -125,7 +124,6 @@
"postgraphile-log-consola": "^1.0.1",
"postgraphile-plugin-connection-filter": "^2.2.2",
"react": "^18.2.0",
"react-cookie": "^6.1.0",
"react-datepicker": "^4.10.0",
"react-dom": "^18.2.0",
"react-is": "^17.0.2",
Expand Down
10 changes: 0 additions & 10 deletions app/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,15 @@ app.prepare().then(async () => {
server.use(graphQlMiddleware());
server.use(
lusca.csrf({
// csrf: true,
xframe: "SAMEORIGIN",
xssProtection: true,
cookie: "qwerty",
})
);
// server.use((req, res, next) => {
// res.get("X-CSRF-Token");
// brianna(req, res, next);
// });

server.use(attachmentDeleteRouter);
server.use(attachmentDownloadRouter);

server.get("*", async (req, res) => {
// console.log("$$$$$$$$$$$$$$$$$$$$$$res.locals._csrf", res.locals._csrf);
// res.cookie("CSRF-TOKEN", res.locals._csrf);
// console.log("res&&&&", res);

return handle(req, res);
});

Expand Down
113 changes: 1 addition & 112 deletions app/server/middleware/attachmentDeleteRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { performQuery } from "./graphql";
import { Storage } from "@google-cloud/storage";
import config from "../../config";

// export const brianna = (req, res, next) => {
export const attachmentDeleteRouter = Router();
console.log("attachmentDeleteRouter", attachmentDeleteRouter);

const attachmentDetailsQuery = `query AttachmentDetailsQuery($attachmentId: ID!){
attachment(id: $attachmentId) {
Expand Down Expand Up @@ -33,8 +31,6 @@ const deleteAttachmentMutation = `mutation deleteAttachmentMutation($input: Dele
}
`;
const handleDelete = async (req, res, next) => {
console.log("************im in handle delete");
console.log("req.header", req.header);
try {
const attachmentQueryVariables = {
attachmentId: req.params.attachmentId,
Expand All @@ -44,7 +40,7 @@ const handleDelete = async (req, res, next) => {
attachmentQueryVariables,
req
);
console.log("queryResponse", queryResponse);

const {
data: {
attachment: { file, id },
Expand Down Expand Up @@ -77,116 +73,9 @@ const handleDelete = async (req, res, next) => {

const response = await storageClient.bucket(bucketName).file(file).delete();

// res.setHeader("X-CSRF-Token", document.cookie);
console.log("!!!!!!!!!!!response[0].statusCode", response[0].statusCode);
return res.sendStatus(response[0].statusCode);
} catch (error) {
next(error);
}
};
attachmentDeleteRouter.delete("/delete/:attachmentId", handleDelete);

// attachmentDeleteRouter.delete(
// "/delete/:attachmentId",
// () =>
// // {
// // console.log("*********about to handle delete");
// // handleDelete(req, res, next);
// // }
// handleDelete
// );
// next();
// };

// export const brianna = (req, res, next) => {
// const attachmentDeleteRouter = Router();
// console.log("attachmentDeleteRouter", attachmentDeleteRouter);

// const attachmentDetailsQuery = `query AttachmentDetailsQuery($attachmentId: ID!){
// attachment(id: $attachmentId) {
// file
// id
// }
// }`;

// const discardProjectAttachmentFormChangeMutation = `mutation discardProjectAttachmentFormChangeMutation(
// $input: DiscardProjectAttachmentFormChangeInput!
// ) {
// discardProjectAttachmentFormChange(input: $input) {
// formChange {
// id
// }
// }
// }`;

// const deleteAttachmentMutation = `mutation deleteAttachmentMutation($input: DeleteAttachmentInput!) {
// deleteAttachment(input:$input){
// attachment {
// id
// }
// }
// }
// `;
// const handleDelete = async (req, res, next) => {
// console.log("************");
// console.log("req.header", req.header);
// try {
// const attachmentQueryVariables = {
// attachmentId: req.params.attachmentId,
// };
// const queryResponse = await performQuery(
// attachmentDetailsQuery,
// attachmentQueryVariables,
// req
// );

// const {
// data: {
// attachment: { file, id },
// },
// } = queryResponse;
// // delete the form_change related to the attachment
// const attachmentFormChangeResponse = await performQuery(
// discardProjectAttachmentFormChangeMutation,
// req.body.variables,
// req
// );

// // delete the attachment from the attachment table
// const deleteAttachmentResponse = await performQuery(
// deleteAttachmentMutation,
// { input: { id } },
// req
// );

// if (
// queryResponse.errors ||
// attachmentFormChangeResponse.errors ||
// deleteAttachmentResponse.errors
// ) {
// throw new Error(`Failed to delete attachment`);
// }

// const storageClient = new Storage();
// const bucketName = config.get("attachmentsBucket");

// const response = await storageClient
// .bucket(bucketName)
// .file(file)
// .delete();

// // res.setHeader("X-CSRF-Token", document.cookie);
// return res.sendStatus(response[0].statusCode);
// } catch (error) {
// next(error);
// }
// };
// console.log("res.get", res.get("_csrf"));
// console.log("res.getX-CSRF-Token", res.get("X-CSRF-Token"));
// console.log("req.cookie", req.cookies);
// console.log("req.headers", req.headers);
// attachmentDeleteRouter.delete("/delete/:attachmentId", () => {
// console.log("*******************in ");
// return handleDelete(req, res, next);
// });
// };
3 changes: 0 additions & 3 deletions app/server/middleware/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ export async function performQuery(query, variables, request: Request) {
pgSettings: settings,
},
async (context) => {
console.log("**************");
console.log("context", context);
console.log("**************");
// Execute your GraphQL query in this function with the provided
// `context` object, which should NOT be used outside of this
// function.
Expand Down
3 changes: 0 additions & 3 deletions app/server/middleware/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const PgSession = connectPgSimple(expressSession);
// True if the host has been configured to use https
const secure = /^https/.test(config.get("host"));
const secret = config.get("sessionSecret");
console.log("************");
console.log("secret", secret);
console.log("************");

const session = () => {
const store = new PgSession({
Expand Down
29 changes: 1 addition & 28 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2197,11 +2197,6 @@
dependencies:
"@types/node" "*"

"@types/cookie@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.5.1.tgz#b29aa1f91a59f35e29ff8f7cb24faf1a3a750554"
integrity sha512-COUnqfB2+ckwXXSFInsFdOAWQzCCx+a5hq2ruyj+Vjund94RJQd4LG2u9hnvJrTgunKAaax7ancBYlDrNYxA0g==

"@types/eslint-scope@^3.7.3":
version "3.7.4"
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.4.tgz#37fc1223f0786c39627068a12e94d6e6fc61de16"
Expand Down Expand Up @@ -2256,7 +2251,7 @@
dependencies:
"@types/unist" "*"

"@types/hoist-non-react-statics@*", "@types/hoist-non-react-statics@^3.3.1":
"@types/hoist-non-react-statics@*":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
Expand Down Expand Up @@ -3589,11 +3584,6 @@ braces@^3.0.1, braces@~3.0.2:
dependencies:
fill-range "^7.0.1"

browser-cookies@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/browser-cookies/-/browser-cookies-1.2.0.tgz#fca3ffb9b6a63aadc4d8c0999c6b57d0fa7d29b5"
integrity sha512-cg2WuoOJo+F+g2XjEaP8nmeRp1vDHjt7sqpKJMsTNXKrpyIBNVslYJeehvs6FEddj8usV2+qyRSBEX244yN5/g==

browser-process-hrtime@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626"
Expand Down Expand Up @@ -8912,15 +8902,6 @@ react-colorful@^5.1.2:
resolved "https://registry.yarnpkg.com/react-colorful/-/react-colorful-5.5.1.tgz#29d9c4e496f2ca784dd2bb5053a3a4340cfaf784"
integrity sha512-M1TJH2X3RXEt12sWkpa6hLc/bbYS0H6F4rIqjQZ+RxNBstpY67d9TrFXtqdZwhpmBXcCwEi7stKqFue3ZRkiOg==

react-cookie@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/react-cookie/-/react-cookie-6.1.0.tgz#1561b822d27e21ded17d1a24f9fd5257804a3ffb"
integrity sha512-j/q0kf4f8kK7zXyTdGEebtZ3IKhVCPZVL3pf6y9/KlfFThxRjb+xvgdKAvRB2VrdkXyu9Qbrb/VuiFUNK6/3+g==
dependencies:
"@types/hoist-non-react-statics" "^3.3.1"
hoist-non-react-statics "^3.3.2"
universal-cookie "^6.0.0"

react-datepicker@^4.10.0:
version "4.10.0"
resolved "https://registry.yarnpkg.com/react-datepicker/-/react-datepicker-4.10.0.tgz#3f386ac5873dac5ea56544e51cdc01109938796c"
Expand Down Expand Up @@ -10420,14 +10401,6 @@ unique-string@^2.0.0:
dependencies:
crypto-random-string "^2.0.0"

universal-cookie@^6.0.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/universal-cookie/-/universal-cookie-6.1.0.tgz#9b631092f77a2b91d1ec153be5e16465ce95b177"
integrity sha512-QBpQWkFJyH9D6nP1ZjPuLDdrgYr3y9ti8OTWf6uWcZwtY06de5f10GPYv3v68LIYWU0a9J2ZF5xFR5gOdD5ZaQ==
dependencies:
"@types/cookie" "^0.5.1"
cookie "^0.5.0"

universalify@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
Expand Down

0 comments on commit 23fb3a8

Please sign in to comment.