Next.js Discord

Discord Forum

Route Handlers error

Answered
Mandarin fish posted this in #help-forum
Open in Discord
Mandarin fishOP
I'm trying to create protected router through route handlers but I'm getting the error "TypeError: module1.render is not a function".
This is my code:
export async function GET(request: NextRequest) {
    const auth = getAuth(firebase_app);
    onAuthStateChanged(auth, (user) => {
        if (user) {
            return NextResponse.next()
        } else {
            return NextResponse.redirect("/")
        }
    })
}

What am I doing wrong?
Answered by Eric Burel
you need to put this code in the root middleware
View full answer

3 Replies

You seem to confuse middleware and route handlers
you need to put this code in the root middleware
Answer
".next()" doesn't make sense in a route handler as there is nothing "next"