Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch a new WordPress Nonce if the current one is expired. #28

Open
calvinalkan opened this issue May 18, 2023 · 1 comment
Open

Fetch a new WordPress Nonce if the current one is expired. #28

calvinalkan opened this issue May 18, 2023 · 1 comment

Comments

@calvinalkan
Copy link

The Gutenberg editor always fetches a new WordPress nonce when the current one is expired, but the user is still logged in.

WordPress/gutenberg#16683

FluentCRM should do the same.

The WP-Rest API will always return this error for expired nonces for logged-in users.

return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie check failed' ), array( 'status' => 403 ) );

From rest_cookie_check_errors.

I think this is even handled automatically if you use the official client JS for the rest API.

	// Send a refreshed nonce in header.
	rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
@calvinalkan
Copy link
Author

You can easily test this by adding this core hook:

add_filter( 'nonce_life', function() {
    return 5;
} );

Then load a FluentCRM page,

Wait 5 secs, and then you won't be able to change anything until you do a crtl+R, even though you are logged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant