Next.js Discord

Discord Forum

Bundling of edge function failed

Unanswered
Ferruginous Hawk posted this in #help-forum
Open in Discord
Ferruginous HawkOP
I had a authentication setup using Auth.js v5. Signed in user information was accessed in components through the session session: { user: {id: string; email: string; name: string;}}

However, when user update their names, the session data is not updated, so I revised session in auth.config to fetch session data from db (especially after making changes) instead of token.

Issue is that I am now unable to complete deployment on Netlify-Bundling of edge function failed, indicating a misconfiguration in my middleware. I had imported {auth} from auth.config and that seemed to have been the cause of the issue.

I undid the changes and the issue seems to persist, and I am unsure where else to look.

Full error message here: https://pastebin.com/WQeTVLab

2 Replies

Ferruginous HawkOP
I just need to redirect users to /dashboard if they are logged-in.

import { auth } from "../auth.config";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export default async function middleware(request: NextRequest) {
  const protectedRoutes = ['/dashboard', '/settings', '/home', '/chat']

  const session = await auth();
  const isLoggedIn = !!session?.user;

  const { pathname } = request.nextUrl;

  // const isDashboard = pathname.startsWith("/dashboard");
  const isProtected = protectedRoutes.some(route => pathname.startsWith(route));
  const isAuthPage = pathname === "/auth/login";

  if (isProtected && !isLoggedIn) {
    return NextResponse.redirect(new URL("/auth/login", request.url));
  }

  if (isAuthPage && isLoggedIn) {
    return NextResponse.redirect(new URL("/dashboard", request.url));
  }

  return NextResponse.next();
}

export const config = {
  matcher: [
    // Protected routes
    "/dashboard/:path*",
    "/settings/:path*",
    // Auth routes
    "/auth/signin",
    "/auth/signup",
  ],
};
No issue when I remove import {auth} from "~/auth.config

And this is my auth.config.ts file