jonathan-dejong / simple-jwt-authentication

Extends the WP REST API using JSON Web Tokens Authentication as an authentication method.
GNU General Public License v3.0
87 stars 25 forks source link

'Updating failed' or 'Publishing failed' error with 500 status when using Gutenberg #40

Closed boxybird closed 5 years ago

boxybird commented 5 years ago

When the simple-jwt-authentication plugin is active and you try to save as draft or publish a post using Gutenberg, the network returns a 500 error and the editor displays either 'Updating failed' or 'Publishing failed'. If disabled, all is fine. Any thoughts?

jonathan-dejong commented 5 years ago

Hi @boxybird

Hmm honestly I've not tried it with Gutenberg yet.. Could you enable WP_DEBUG and dig a little deeper on the errors you're getting and post back here?

boxybird commented 5 years ago

With WP_DEBUG enabled the error appears to be a memory issue. The only message is "PHP Fatal error: Allowed memory size of 2097152000 bytes exhausted".

To be sure it wasn't my local setup causing the lack of memory issue I added "define('WP_MEMORY_LIMIT', '2056M');" to wp-config.php. This should be more than memory and yet I still get the same error.

jonathan-dejong commented 5 years ago

Hmm sounds like it could be an infinite loop or a memory leak of some other kind.. would you mind testing some stuff. Activate the plugin and then open up the plugin file simple-jwt-authentication/includes/class-simple-jwt-authentication-rest.php and try to comment out one of the filter hooks in the __construct at a time and see wether the saving of a post starts to work or not after each.

I think it has to be one of those! Most likely either the determine_current_user or rest_pre_dispatch hooks.

boxybird commented 5 years ago

You're right, it's the determine_current_user hook.

I found the solution here: https://github.com/Tmeister/wp-api-jwt-auth/commit/3d61a660ade3637c79dd8f5acbdeaa0b0a30e798

jonathan-dejong commented 5 years ago

@boxybird could you try out this branch and see if that does the trick for you :) https://github.com/jonathan-dejong/simple-jwt-authentication/tree/bugfix/gutenberg-leak

boxybird commented 5 years ago

@jonathan-dejong Works beautifully! Thanks.

jonathan-dejong commented 5 years ago

Great! I'ts been merged with master now :)