i integrate next-csrf into my site which i build in nextjs but i am facing this issue
satishktak1988 opened this issue · 14 comments
can any one let me know whats the issue
yeah same issue, this package doesnt work.
same issue
same issue
same issue, any solution?
same issue
@0lv3r4 any news about it ?
Same issue, no hints toward a solution?
Same issue, no hints toward a solution?
I did use another solution. I get csrf funtion from next-auth pkg.
it's epic lol ))) the same issue. Guys, you are proposing to use your lib but it doesn't work
I am not using this library anymore, but this issue can be fixed by applying these patches to your fork and then running npm run build
diff --git a/rollup.config.js b/rollup.config.js
index 1bb0b45..b0ed382 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -13,6 +13,6 @@ export default [
{ file: pkg.module, format: "es" },
],
plugins: [typescript(), commonjs(), resolve(), analyze()],
- external: ["crypto"],
+ external: ["crypto", "util"],
},
];
diff --git a/src/middleware/csrf.test.ts b/src/middleware/csrf.test.ts
index 5a1c663..9eee9e0 100644
--- a/src/middleware/csrf.test.ts
+++ b/src/middleware/csrf.test.ts
@@ -30,7 +30,8 @@ describe("csrf middleware", () => {
csrf((req: NextApiRequest, res: NextApiResponse) => {
return res.status(200).json({ message: "Hello, world." });
}),
- apiPreviewPropsMock
+ apiPreviewPropsMock,
+ true
);
};
Hey all. Sorry, I haven't had time to fix this, but I will test @sushantdhiman's solution and apply it soon (I hope today).
But as an alternative, you can use the CSRF function from https://next-auth.js.org/ just like @kriscannabis mentioned.
Getting this error as well. I was able to sort of fix it.
When trying to build I get a warning for circular dependencies in util
(!) Circular dependencies node_modules\assert\node_modules\util\util.js -> node_modules\assert\node_modules\inherits\inherits.js -> node_modules\assert\node_modules\util\util.js node_modules\assert\node_modules\util\util.js -> node_modules\assert\node_modules\inherits\inherits.js -> C:/Users/jkngsly/Desktop/next-csrf/next-csrf/node_modules/assert/node_modules/util/util.js?commonjs-proxy -> node_modules\assert\node_modules\util\util.js created dist/next-csrf.js, dist/next-csrf.esm.js in 3s
webpack/webpack#1019 (comment)
To quote @jhnns:
"Yep, it's a circular dependency. util
uses console.log()
which triggers webpack to include console-browserify
which requires assert
which requires
util → voilà :)"
So I commented out the following:
node_modules/util/utils.js line 546
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
After running npm run build
again and the circular-dependencies error was gone, I copied dist/next-csrf.js
into my project, imported, and ran it successfully.
Getting the same issue as above.