Thanks to Jacob Peattie, I was able to solve this issue.
You have to include a nonce from the WordPress Javascript API in your REST API requests if you wish to use information about the current user.
From the WordPress documentation:
If no nonce is provided the API will set the current user to 0,
turning the request into an unauthenticated request, even if you’re
logged into WordPress.
In other words, the endpoint will get excecuted even without a nonce, but any attempt to fetch information about the current user will fail/result in an empty user object.
Related Posts:
- Nonce retrieved from the REST API is invalid and different from nonce generated in wp_localize_script
- REST API: Backbone and custom endpoint
- Gutenberg custom block plugin with custom image sizes
- Get loading state of wp data selector
- WP REST – video and audio players
- Headless WordPress: How to authenticate front end requests?
- Post to WordPress using REST API from external site
- How to handle malformed response from WP REST API?
- Rest API authentication issue when called from fetch request in bundle.js
- Get HTTP response code on non-2xx apiFetch request
- Rest API invalid nonce with Backbone Client
- WP REST API Post Status Using JavaScript
- How to transform a legacy widget into a block
- Authentication with the Rest API when using an External Application
- Get Block Attributes in JSON REST API
- Setting/unsetting terms using the Backbone JavaScript client
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- Search for a keyword across post types in a Gutenberg component
- Using apiFetch for retrieving post data in Gutenberg
- Get terms of a taxonomy using useSelect
- Return ‘X-WP-Total’ from headers in response
- How to render WP Rest-API Endpoints in a React.js Theme with Woocommerce
- Retrieving data about comments and likes
- how to let users upload their custom cover image
- how to use nimble-API and Display data?
- Check if user can in javascript
- wp-api Backbone JS Client fetch options
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- Rest API and how to deal with it in server side
- Access checks with custom REST endpoints and backbone
- Can I get the user name in JavaScript?
- [Vue warn]: Error in render: “TypeError: Cannot read property ‘wp:featuredmedia’ of undefined – REST API
- Update block once an API request returns with a value
- How to improve WP-Rest atrocious response time?
- I would like to retrive JSON value and display it in wordpress page or widget
- Connecting a wordpress site to an AngularJS APP
- WordPress REST API response is empty in browser and script, but not in Postman
- WP REST API – “rest_user_cannot_view” ONLY on specific users
- Get Comment Text via REST API
- Split string into array
- convert Hsl to rgb and hex
- “Uncaught TypeError: Cannot read property ‘style’ of null at.. “
- Difference between document.referrer and window.parent.location.href
- JavaScript replace/regex
- how to render a react component using ReactDOM Render
- What does “javascript:void(0)” mean?
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- OnChange event using React JS for drop down
- how to get the last character of a string?
- Set timeout for ajax (jQuery)
- Escaping Discord subset of markdown
- ESLint Parsing error: Unexpected token
- Angular ForEach in Angular4/Typescript?
- Timers in React Native (this.setTimeout)
- bootstrap-datetimepicker for bootstrap 4
- Proper way to wait for one function to finish before continuing?
- XMLHttpRequest module not defined/found
- document.getElementsByClassName().innerHTML always returns “undefined”
- Bower: ENOGIT Git is not installed or not in the PATH
- Converting an object to a string
- SyntaxError: expected expression, got ‘<'
- Attaching ‘onclick’ event to D3 chart background
- declaration or statement expected javascript/typescript
- The preferred way of creating a new element with jQuery
- How to pass parameters using ui-sref in ui-router to controller
- HTML/Javascript change div content
- How do you remove all the options of a select box and then add one option and select it with jQuery?
- Add and remove multiple classes in jQuery
- How To Save Canvas As An Image With canvas.toDataURL()?
- NPM install fails with node-gyp
- How do I download a file with Angular2 or greater
- What are alternatives to document.write?
- What are differences between SystemJS and Webpack?
- How to find if div with specific id exists in jQuery?
- TypeError: $ is not a function WordPress
- Fully responsive HTML5 video
- How to add JavaScript code on WordPress properly?
- Disable unneeded scripts in a wordpress installation
- How to stop a Gutenberg Block from firing multiple GET Requests?
- Gutenberg getMedia() in post query doesn’t return all featured images
- Can I change an external script’s HTML?
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- Cannot use characters ” in jQuery script in WordPress
- How to install cool javascript feature in WordPress?
- Is it possible to create new user from external form using REST API?
- Normal for scripts to be loaded after body tag?
- Query String Filtering API
- JS inside modal doesn’t work
- How to Get Post Meta in .Js File [duplicate]
- Script not working in post content
- How to identify which javascript is being executed
- How could I add load more posts to my theme? [closed]
- How to keep close a sub-menu under homepage? [closed]
- Javascript 2 elements dependent onclick .toggle [closed]
- How to load JavaScript modules with script_loader_tag hook?
- Why is this script not working?
- How can create a custom plugin to call my webapi after any registration or membership plugin functionality
- How to securely set dynamic HTML content with JavaScript?
- Astra Mobile Cart Drawer is blank on home page
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?