Skip to content

chore(nextjs): Add tests covering the new middleware matcher - #3741

Merged
nikosdouvlis merged 1 commit into
mainfrom
nikos/add-matcher-test
Jul 18, 2024
Merged

chore(nextjs): Add tests covering the new middleware matcher#3741
nikosdouvlis merged 1 commit into
mainfrom
nikos/add-matcher-test

Conversation

@nikosdouvlis

Copy link
Copy Markdown
Member

Description

The matcher we currently document breaks Clerk for the following scenario.

  • Have an app using the currently documented matcher
  • Have a URL structure similar to /articles/:article-slug. :article-slug would be something like ${article_title}_${article_id} , eg: /article/hello-team-support_123a - pretty common stuff so far.

If an article contains a . in its name, eg /article/i-use-clerk.com-and-why-you-should-too_123, then auth() and related helpers will fail because the matcher will not match the request URL and the middleware will be skipped.

This bug recently hit a few customers. This PR updates the matcher with a simplified version that no longer handles files as an edge case. We want to update our own dashboard first to further test the new matcher, before we reach out to the customers with the updated version.

The new matcher works for all cases tested in this PR. In comparison, the old matcher we used (shown below) failed for at least the following cases:

    ✕ triggers the middleware for "/sl.ug-123" (1 ms)
    ✕ triggers the middleware for "/sl.ug"
    ✕ triggers the middleware for "/download?filename=1.jpg"
    ✕ triggers the middleware for "/download/?filename=1.jpg" (1 ms)
    ✕ triggers the middleware for "/download?test=1&filename=1.jpg"
    ✕ triggers the middleware for "/download?filename=1.jpg&test=1"
    ✕ triggers the middleware for "/download?filename=1.png&test=1"
    ✕ triggers the middleware for "/file.json" (1 ms)
    ✕ triggers the middleware for "/file.json/"
    ✕ triggers the middleware for "/a/b.json"

Important: any change here needs to be reflected in the docs + the dashboard quickstart page.

For reference, the old matcher was:

export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
};

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot

changeset-bot Bot commented Jul 17, 2024

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: be38bd2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@nikosdouvlis nikosdouvlis self-assigned this Jul 17, 2024
@nikosdouvlis
nikosdouvlis force-pushed the nikos/add-matcher-test branch from a07ac4d to be38bd2 Compare July 17, 2024 12:15
@nikosdouvlis
nikosdouvlis merged commit dc87bbd into main Jul 18, 2024
@nikosdouvlis
nikosdouvlis deleted the nikos/add-matcher-test branch July 18, 2024 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants