#60868 closed defect (bug) (invalid)
Persistence layer tries to make a REST API call to '/wp/v2/users/me' when user is not logged in
Reported by: | chamois_blanc | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | 6.4.3 |
Component: | Script Loader | Keywords: | |
Focuses: | javascript | Cc: |
Description
The code below from wp-includes/js/dist/preferences-persistence.js
tries to make a REST API call to '/wp/v2/users/me?context=edit', even when not logged in. On my site, this returns a 401 (maybe due to a security setting).
Would it not be possible to check whether the user is logged in first, either through some WP JS data or a JS cookie, and not do this call if the user is not logged in?
function create({ preloadedData, localStorageRestoreKey = 'WP_PREFERENCES_RESTORE_DATA', requestDebounceMS = 2500 } = {}) { let cache = preloadedData; const debouncedApiFetch = debounceAsync((external_wp_apiFetch_default()), requestDebounceMS); async function get() { if (cache) { return cache; } const user = await external_wp_apiFetch_default()({ path: '/wp/v2/users/me?context=edit' });
Change History (4)
#2
@
7 months ago
- Component changed from General to Script Loader
- Focuses rest-api privacy removed
- Keywords 2nd-opinion removed
Definitely ran into this too.
Best to report this on the Gutenberg repo though where that code is maintained.
The logged-in check must not depend on the DOM, that isn‘t reliable.
#3
@
7 months ago
- Resolution set to invalid
- Status changed from new to closed
Closing as it turns out this was due to the Updraft Central plugin.
See: https://wordpress.org/support/topic/uc-gutenberg-blocks-loaded-on-all-frontend-pages/#post-17549604
Checking that the user is logged in could be as simple as:
and same remark for the
PUT
request.