Title: Next-auth middleware broken after installing sentry · Issue #9681 · getsentry/sentry-javascript · GitHub
Open Graph Title: Next-auth middleware broken after installing sentry · Issue #9681 · getsentry/sentry-javascript
X Title: Next-auth middleware broken after installing sentry · Issue #9681 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/9681
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Next-auth middleware broken after installing sentry","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [X] I have reviewed the documentation https://docs.sentry.io/\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/nextjs\n\n### SDK Version\n\n7.82.0\n\n### Framework Version\n\n_No response_\n\n### Link to Sentry event\n\nhttps://autores.sentry.io/issues/4676163831/events/d4dbf6490ef14a9392b2e02880e667ac/\n\n### SDK Setup\n\nDependencies:\r\n - next v13.4.5 (using the app dir)\r\n - next-auth v4.23.1 (also tried with the latest version, didn't help)\r\n - sentry v7.82.0\r\n\r\nMy middleware.ts file (in the root dir, not `src`):\r\n``` javascript\r\nimport { getToken } from \"next-auth/jwt\"\r\nimport { withAuth } from \"next-auth/middleware\"\r\nimport { NextResponse } from \"next/server\"\r\n\r\nexport default withAuth(\r\n async function middleware(req) {\r\n const token = await getToken({ req })\r\n const isAuth = !!token\r\n // more auth logic, omitted\r\n return NextResponse.redirect(new URL(\"/\", req.url))\r\n },\r\n {\r\n callbacks: {\r\n async authorized() {\r\n // This is a work-around for handling redirect on auth pages.\r\n // We return true here so that the middleware function above\r\n // is always called.\r\n return true\r\n },\r\n },\r\n }\r\n)\r\n\r\n// specify paths to be handled by this middleware\r\nexport const config = {\r\n matcher: [ \"/dashboard\"],\r\n}\r\n\r\n```\r\nMy SDK setup just uses the default values generated by the sentry setup wizard.\r\n\r\nAfter installing sentry and running `npm run dev`, I get this error:\r\n```\r\nAttempted import error: 'withAuth' is not exported from 'next-auth/middleware' (imported as 'withAuth').\r\n- error middleware.ts (5:0) @ \u003cunknown>\r\n- error (0 , next_auth_middleware__WEBPACK_IMPORTED_MODULE_2__.withAuth) is not a function\r\n```\r\n\r\nI reverted all the changes made by the sentry wizard and ran the dev server again, confirmed no issues.\n\n### Steps to Reproduce\n\n1. create a next app using `create-next-app`\r\n2. install next-auth and create a middleware.ts file in the root dir with the contents above\r\n3. install @sentry/nextjs and run the sentry setup wizard\r\n4. run `npm run dev`\n\n### Expected Result\n\nNo errors when running the dev server\n\n### Actual Result\n\nimport error in `middleware.ts`:\r\n```\r\nAttempted import error: 'withAuth' is not exported from 'next-auth/middleware' (imported as 'withAuth').\r\n- error middleware.ts (5:0) @ \u003cunknown>\r\n- error (0 , next_auth_middleware__WEBPACK_IMPORTED_MODULE_2__.withAuth) is not a function\r\n```","author":{"url":"https://github.com/maliesa96","@type":"Person","name":"maliesa96"},"datePublished":"2023-11-28T04:11:57Z","url":"https://github.com/getsentry/sentry-javascript/issues/9681"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:31541c62-d912-f9fc-d021-18c839575389 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96A4:2EAA8D:B5B37:FA21D:6B042DDA |
| html-safe-nonce | 642fc9eb3a12f206b611a42774d7ae81ea141c1c650b84c422265f1deba335e3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkE0OjJFQUE4RDpCNUIzNzpGQTIxRDo2QjA0MkREQSIsInZpc2l0b3JfaWQiOiI3OTg1MDg1MzM2MDI2MDk5MTYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3d2b0f5153288cab945ef85d8097fa9ea85328e3a4ecef9c6291e95e768706ff |
| hovercard-subject-tag | issue:2013580869 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/9681/issue_layout |
| twitter:image | https://opengraph.githubassets.com/236444135e3291be80ebfe82c9eadc3fd38c6f864c5783d919c200485f11d8ec/getsentry/sentry-javascript/issues/9681 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/236444135e3291be80ebfe82c9eadc3fd38c6f864c5783d919c200485f11d8ec/getsentry/sentry-javascript/issues/9681 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maliesa96 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width