Using Mongoose Model inside NextJS middleware results in undefined model error.
Unanswered
Palm Warbler posted this in #help-forum
Palm WarblerOP
Hi, I have a
Any clue why this could be happening?
dbConnect()
method and a Mongoose model that I am able to use in API routes, but when I try to use these in a middleware, it throws an undefined model error:- error src\models\User.ts (32:0) @ <unknown>
- error Cannot read properties of undefined (reading 'User')
>32| export default mongoose.models.User ||
33 | mongoose.model("User", UserSchema);
Any clue why this could be happening?