Wordpress Auth + Nonces + Ajax + No Templating - Cookie nonce is invalid
It seems that when you call $my_nonce = wp_create_nonce('wp_rest');
the nonce is created with the old session cookie, even when you call wp_set_auth_cookie
and wp_set_current_user
. But in the next request the session is updated, meaning that the nonce is wrong.
As in the answer, add the following hook (functions.php for example) to force an update of the cookie:
function my_update_cookie( $logged_in_cookie ){ $_COOKIE[LOGGED_IN_COOKIE] = $logged_in_cookie; } add_action( 'set_logged_in_cookie', 'my_update_cookie' );