auth-helpers
auth-helpers copied to clipboard
Upcoming Next.js middleware changes
In the Next.js package, there is a function which is withMiddlewareAuth
. In the upcoming breaking changes to Next.js version 12.2, they completely alter how middleware works. I would just like to confirm that this update does not affect this package, as it is a crucial component of my app.
Now that 12.2 is out it looks like some changes will be required given that there is only a single middleware per application. I'll look into what a new approach might look like when I can. For now, consider withMiddlewareAuth
broken in 12.2
A PR is welcomed if anyone has a fix for this change. I haven't had a chance to look into this change as yet so won't be able to work on a fix at the moment.
Been looking at https://nextjs.org/docs/messages/middleware-upgrade-guide and I think placing the middleware.js
at the same level as your pages
folder will do the trick and than do something like:
middleware.js
import { withMiddlewareAuth } from '@supabase/auth-helpers-nextjs/middleware';
export function middleware(request) {
withMiddlewareAuth({ redirectTo: '/login' });
}
export const config = {
matcher: ['/dashboard/:path*'],
}
But weirdly enough I get the below error, which makes no sense to me
./middleware.js:1:0
Module not found: Can't resolve '@supabase/auth-helpers-nextjs/middleware'
> 1 | import { withMiddlewareAuth } from '@supabase/auth-helpers-nextjs/middleware';
Hey @Jordaneisenberger,
Try importing it from @supabase/auth-helpers-nextjs/dist/middleware
. This seems to be where it is being exported from at the moment.