-
Notifications
You must be signed in to change notification settings - Fork 22
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
Not working with latest next 13 #35
Comments
@suil works for me, what's your middleware.ts like? I just copied the one from examples. |
Error: The Edge Function "middleware" is referencing unsupported modules: // middleware.js
import { createNextAuthMiddleware } from 'nextjs-basic-auth-middleware'
export const middleware = createNextAuthMiddleware(options)
export const config = {
matcher: ['/(.*)'], // Replace this with your own matcher logic
} "nextjs-basic-auth-middleware": "^3.1.0", |
@phsantiago const options = {
users: [{ name: "username", password: "password" }],
}; |
@myrkytyn sorry, I deleted the repo, so I'm not sure about the version, I think it was 13.4 because was a brand new installation. I could make it work but with a different implementation in another repo:
//middleware.js
import { NextResponse } from "next/server";
import checkBasicAuth from "@utils/middleware/checkBasicAuth";
export function middleware(request) {
if (
!checkBasicAuth(request.headers.get("authorization"), {
username: process.env.AUTH_USERNAME,
password: process.env.AUTH_PASSWORD,
})
) {
return NextResponse.rewrite(
`${request.nextUrl.protocol}//${request.nextUrl.host}/401`,
{
status: 401,
headers: {
"WWW-Authenticate": 'Basic realm="Secure Area"',
},
},
);
}
return NextResponse.next();
} |
The middleware.ts/js of NextJS 13 must be placed in the root directory, and it will not work if placed under src. |
Somehow it's not working with latest project structure that are generated by
npx create-next-app@latest
The text was updated successfully, but these errors were encountered: