Error : adonisjs Cannot read properties of undefined (reading 'get') when enable csrf token

53 views Asked by At

I'm new in Adonisjs and I'm using it for the rest API when I set ShieldConfig["csrf"] enabled:true I got this error

 "type": "TypeError",
 "message": "Cannot read properties of undefined (reading 'get')",

and I'm using the below versions

"@adonisjs/core": "^5.9.0",
"@adonisjs/repl": "^3.1.11",
"@adonisjs/shield": "^7.1.1",

and I add this to start/kernel.ts file

Server.middleware.register([
  () => import("@ioc:Adonis/Core/BodyParser"),
  () => import("@ioc:Adonis/Addons/Shield"),
]);

when I set ShieldConfig["csrf"] enabled:false I got no error

1

There are 1 answers

0
Eliferd On

I've faced the same issue and it seems like CSRF indirectly depends on @adonisjs/session package.

I resolved the issue by installing and configuring it on my case. But you get an unused session cookie in addition to the XSRF/CSRF one...

https://v5-docs.adonisjs.com/guides/session