Using _middleware in next-auth redirects to favicon.ico

Viewed 162

To protect all pages on the site without authorization, I use _middleware.js. ./pages/_middleware.js

export { default } from "next-auth/middleware";

When I go to the site without authorization, I am redirected to the login form. But after I fill it out and log in, it redirects me to http://localhost:3000/favicon.ico Why on favicon.ico I can't understand. Maybe someone will explain.

1 Answers

Not sure what causes this but setting a redirect callback in NextAuthOptions seems to solve it.

export const authOptions: NextAuthOptions = {
...
callbacks: {
    async redirect({ url, baseUrl }) {
       return baseUrl;
    },
  }
};
Related