Hello, I’ve deployed my app to Vercel and am using the NextJS SDK version 4.0.0-beta.14.
I’ve set up the relevant endpoints in my app for logging in, fetching profile data, logging out like so:
/auth/login
/auth/logout
/auth/profile
This is my middleware function in the app:
export async function middleware(request: NextRequest) {
const authResponse = await auth0Client.middleware(request);
if (request.nextUrl.pathname.startsWith("/auth")) {
return authResponse;
}
if (request.nextUrl.pathname.startsWith('/profile')) {
return profileMiddleWare(request);
}
if (request.nextUrl.pathname.startsWith('/')) {
const existingCookies = request.cookies.get('user');
if (!existingCookies) {
const response = await createUserCookie();
return response;
}
return NextResponse.next();
}
}
I’ve changed the Auth0 application settings so that the login, logout and callback URIs include the Vercel domain + /auth/login (or callback). CORS is also enabled with my Vercel domain.
When I test locally (localhost) I have no issues with /auth/login - I get redirected to login page. But after deploying to Vercel I get a 500 error “MIDDLEWARE_INVOCATION_FAILED” when visiting the login page.
In my Vercel logs I have “Invalid URL” for this and /auth/callback. As for /auth/profile I just get unauthorized 401.
The environmental variables in Vercel are set up to match my client id, secret, etc with Auth0.
I also tried to integrate Auth0 from Vercel’s marketplace but it fails every time, even though a client gets created in my Auth0 apps. I get a message then:
Failed setting an environment variable: Attempted call to the API failed: non-2xx status code. Please contact Vercel for support.
What could be causing these errors? My app was working fine while using /api/auth endpoints before the v4 update. Thanks in advance.
PS - I relied on this guide for migrating to the newest version: