You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next.js introduced breaking changes in their latest v12.2 version (upgrade guide: https://nextjs.org/docs/messages/middleware-upgrade-guide).
Basically, there should only be a root middleware, and not nested ones with _ prepended names.
The new root middleware has a following syntax:
exportasyncfunctionmiddleware(req){if(req.nextUrl.pathname.startsWith("/api/v1/protected")){consttoken=awaitgetToken({ req });if(token){// Authenticated user - allow accessreturnNextResponse.next();}returnNextResponse.redirect(newURL("/api/unauthenticated",req.url));}// Else just pass throughreturnNextResponse.next();}
Here, the req seems to be different from what we know from API routes req
@balazsorban44 my bad - you're right. After updating to 4.9.0 this issue has been resolved.
Stupid me - thought about everything except updating next-auth.... :P
Environment
System:
OS: macOS 12.3.1
CPU: (10) arm64 Apple M1 Pro
Memory: 99.58 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.15.0 - /usr/local/bin/node
npm: 8.5.5 - /usr/local/bin/npm
Browsers:
Chrome: 103.0.5060.114
Firefox: 102.0.1
Safari: 15.4
npmPackages:
next: ^12.2.2 => 12.2.2
next-auth: ^4.3.4 => 4.5.0
react: 18.0.0 => 18.0.0
Reproduction URL
N/A
Describe the issue
Next.js introduced breaking changes in their latest v12.2 version (upgrade guide: https://nextjs.org/docs/messages/middleware-upgrade-guide).
Basically, there should only be a root middleware, and not nested ones with
_
prepended names.The new root middleware has a following syntax:
Here, the
req
seems to be different from what we know from API routesreq
or the old
_middleware.js
files.Passing the
req
from the root middleware togetToken({req})
returnsnull
even if we specify the secretgetToken({req, secret}) //->null
.How to reproduce
getToken()
) using the middleware'sreq
parameter. This step fails.Expected behavior
getToken()
should be useable in a root middleware, since this is how next v12.2 works now.The text was updated successfully, but these errors were encountered: