Skip to content

Instantly share code, notes, and snippets.

@balazsorban44
Last active May 4, 2024 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save balazsorban44/18667ad0d7daf393eaeedb55da702470 to your computer and use it in GitHub Desktop.
Save balazsorban44/18667ad0d7daf393eaeedb55da702470 to your computer and use it in GitHub Desktop.
import { withAuth } from "next-auth/middleware";
export default withAuth(
function middleware(request) {
if (request.nextUrl.pathname !== "/") return;
return Response.redirect(new URL("/home", request.url));
},
// This is NextAuth.js
// Docs: https://next-auth.js.org/configuration/nextjs#pages
// Needs to be the same as your `authOptions.pages`
{ pages: { signIn: "/login" } }
);
// This is Next.js
// Docs: https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
export const config = {
matcher: ["/((?!login).*)"],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment