import { withAuth } from "next-auth/middleware"; export default withAuth( () => { }, { pages: { signIn: `/login`, }, callbacks: { authorized: ({ token, req }) => { const { url, headers, } = req; // check login page const parsedURL = new URL(url); if (parsedURL.pathname.startsWith('/login')) { return true; } // check session auth const authorizedDomains = ["redaranj.com", "digiresilience.org"]; const userDomain = token?.email?.toLowerCase().split("@").pop() ?? "unauthorized.net"; if (authorizedDomains.includes(userDomain)) { return true; } return false; }, } } );