Next.js Discord

Discord Forum

Middleware authConfig is preventing .mp3 files to play

Answered
Spotted Rail posted this in #help-forum
Open in Discord
Spotted RailOP
My /app/authConfig.js
export const authConfig = {
    providers: [],
    pages: {
        signIn: "/signin"
    },
    secret: process.env.AUTH_SECRET,
    callbacks: {
        authorized({ auth, request }) {
            const isLoggedIn = !!auth?.user;
            const isOnDashboard = request.nextUrl.pathname.startsWith("/dashboard");

            if (isOnDashboard) {
                if (isLoggedIn) return true;
                return false;
            } else if (isLoggedIn) {
                return Response.redirect(new URL("/dashboard", request.nextUrl))
            }

            return true;
        }
    }
}
Answered by B33fb0n3
exclude the public folder from your middleware, because the public folder is public
View full answer

9 Replies

Spotted RailOP
/middleware.js
import NextAuth from 'next-auth';
import { authConfig } from './app/authConfig';
 
export default NextAuth(authConfig).auth;

export const config = {
    matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)"],
};
Spotted RailOP
I am loading .mp3 files from public/sounds/
Answer
@B33fb0n3 exclude the public folder from your middleware, because the public folder is public
Spotted RailOP
oh the matcher was causing the issue
exactly. Happy to help
This excludes the public folder
export const config = {
    matcher: "/((?!api|static|.*\\..*|_next).*)",
};