Regarding “SESSION” in the tutorial Page 342,
I get the below error when editing the acronym and click Update.
I have go through in every line of code to see if there are any wrong in my WebsiteController.swift , Also in CreateAcronym.leaf .
But still not found any bug of my code.
Appreciated if you could advise.
{“error”:true,“reason”:“Value of type ‘String’ required for key ‘csrfToken’.”}
So if you remove the #if statement it all works? that would point to a bug in Leaf. If you set the if statement and inspect the returned HTML, does the input not exist?
Hmm you’re right! There’s a bug in the chapter (and from the looks of it, the final project itself) where the editAcronymPostHandler(_:) is decoding CreateAcronymData which expects a CSRF token, but the EditAcronymContext doesn’t have it.
Fixes are - remove the if, you’ll get an empty String, which masks the problem, or pass in a CSRF token to the edit acronym page. Not sure how this got missed in 2 versions and lots of tech edits!
@thammaporn@oliz thanks for spotting this! I’ve fixed it in the next edition of the book and update the GH repo. The fix I’ve gone for is to make csrfToken on CreateAcronymData optional so it doesn’t fail when decoding the data on the edit POST handler:
You then just need to update createAcronymPostHandler(_:data:) to account for the change: