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

Fix 401 token request in WordPressTemplate #1724

Merged
merged 5 commits into from
Jan 12, 2024
Merged

Conversation

blakewilson
Copy link
Contributor

@blakewilson blakewilson commented Jan 12, 2024

Tasks

  • I have signed a Contributor License Agreement (CLA) with WP Engine.
  • If a code change, I have written testing instructions that the whole team & outside contributors can understand.
  • I have written and included a comprehensive changeset to properly document the changes I've made.

Description

This PR skips the useAuth call unless the route is a preview route. Currently, useAuth is running on every page, which in turn makes a request to the token endpoint to see if a user is authenticated.

Related Issue(s):

Testing

  1. Checkout this branch
  2. npm install from the root
  3. npm run build from the root
  4. Run the example project npm run dev -w @faustwp/getting-started-example from the root
  5. Ensure all pages/posts/previews/etc operate as normal while checking to ensure there is not an additional token request made (there will still be a request for the token if experimentalToolbar is enabled)
  6. Ensure useAuth hook operates as normal/expected with and without the new skip option.

Screenshots

Documentation Changes

Closes #1722

@blakewilson blakewilson requested a review from a team as a code owner January 12, 2024 15:26
Copy link

changeset-bot bot commented Jan 12, 2024

🦋 Changeset detected

Latest commit: 44dcba4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@faustwp/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Jan 12, 2024

📦 Next.js Bundle Analysis for @faustwp/getting-started-example

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 246.1 KB (🟡 +55 B)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Copy link
Member

@josephfusco josephfusco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, only seeing the 401 when experimentalToolbar: true, as expected. 💯

I added some testing suggestions to cover the new skip option in useAuth

Co-authored-by: Joe Fusco <josephfusco@users.noreply.github.com>
@blakewilson blakewilson merged commit 085c30d into canary Jan 12, 2024
18 checks passed
@blakewilson blakewilson deleted the fix-401-token-request branch January 12, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants