[wp-trac] [WordPress Trac] #60868: Persistence layer tries to make a REST API call to '/wp/v2/users/me' when user is not logged in

WordPress Trac noreply at wordpress.org
Sat Mar 30 23:02:04 UTC 2024


#60868: Persistence layer tries to make a REST API call to '/wp/v2/users/me' when
user is not logged in
-------------------------------------------+-----------------------------
 Reporter:  chamois_blanc                  |      Owner:  (none)
     Type:  defect (bug)                   |     Status:  new
 Priority:  normal                         |  Milestone:  Awaiting Review
Component:  General                        |    Version:  6.4.3
 Severity:  minor                          |   Keywords:  2nd-opinion
  Focuses:  javascript, rest-api, privacy  |
-------------------------------------------+-----------------------------
 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'
     });
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60868>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list