Middleware Issue on our Nextjs project
We are facing an issue on our existing middleware setup on our nextjs project, we use to check if a user is authenticated before using this code:
but now after upgrading convex auth from 0.0.74 to 0.0.80 we are getting this error:
Middleware.ts file code
Error:
can anyone help me fix this issue.
await convexAuth.isAuthenticated()await convexAuth.isAuthenticated()but now after upgrading convex auth from 0.0.74 to 0.0.80 we are getting this error:
Middleware.ts file code
export default convexAuthNextjsMiddleware(
async (request, { convexAuth }) => {
const url = new URL(request.url);
if (url.pathname === "/login" && (await convexAuth.isAuthenticated())) {
const urlSearchParams = new URL(request.url).searchParams
.get("redirect")
?.replaceAll("/", "");
if (urlSearchParams) {
return NextResponse.redirect(
new URL(`/${urlSearchParams}`, request.url)
);
} else {
return NextResponse.redirect(new URL("/", request.url));
}
}
if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
const url = new URL(request.url);
const pathAfterLocalhost = url.pathname.replace("application", "");
if (pathAfterLocalhost) {
return NextResponse.redirect(
new URL(`/login?redirect=${pathAfterLocalhost}`, request.url)
);
}
return nextjsMiddlewareRedirect(request, "/login");
}
},
{ cookieConfig: { maxAge: 60 * 60 * 24 * 30 } }
);export default convexAuthNextjsMiddleware(
async (request, { convexAuth }) => {
const url = new URL(request.url);
if (url.pathname === "/login" && (await convexAuth.isAuthenticated())) {
const urlSearchParams = new URL(request.url).searchParams
.get("redirect")
?.replaceAll("/", "");
if (urlSearchParams) {
return NextResponse.redirect(
new URL(`/${urlSearchParams}`, request.url)
);
} else {
return NextResponse.redirect(new URL("/", request.url));
}
}
if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {
const url = new URL(request.url);
const pathAfterLocalhost = url.pathname.replace("application", "");
if (pathAfterLocalhost) {
return NextResponse.redirect(
new URL(`/login?redirect=${pathAfterLocalhost}`, request.url)
);
}
return nextjsMiddlewareRedirect(request, "/login");
}
},
{ cookieConfig: { maxAge: 60 * 60 * 24 * 30 } }
);Error:
Server Error
Error: Server Error: could not find api.auth.isAuthenticated. convex-auth 0.0.76 introduced a new export in convex/auth.ts. Add `isAuthenticated` to the list of functions returned from convexAuth(). See convex-auth changelog for more https://github.com/get-convex/convex-auth/blob/main/CHANGELOG.md
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
src\middleware.ts (29:38) @ async eval
> 29 | if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {}Server Error
Error: Server Error: could not find api.auth.isAuthenticated. convex-auth 0.0.76 introduced a new export in convex/auth.ts. Add `isAuthenticated` to the list of functions returned from convexAuth(). See convex-auth changelog for more https://github.com/get-convex/convex-auth/blob/main/CHANGELOG.md
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
src\middleware.ts (29:38) @ async eval
> 29 | if (isProtectedRoute(request) && !(await convexAuth.isAuthenticated())) {}can anyone help me fix this issue.
