Adding Middleware To My App Folder Causes Error
Unanswered
German yellowjacket posted this in #help-forum
German yellowjacketOP
Whenever I add my middleware to my project it gives this error
This is my middleware file inside of app folder
this is my UserModel.js file
This is my middleware file inside of app folder
import { auth } from "@/auth"
export default auth((req) => {
if (!req.auth && req.nextUrl.pathname !== "/login") {
const newUrl = new URL("/login", req.nextUrl.origin)
return Response.redirect(newUrl)
}
})this is my UserModel.js file
import mongoose, { Schema } from "mongoose";
const userSchema = new Schema({
name: {
required: true,
type: String,
},
password: {
required: true,
type: String,
},
email: {
required: true,
type: String,
},
age: {
type: Number,
},
gender: {
type: String,
},
height: {
type: Number,
},
weight: {
type: Number,
},
profilePicture: {
type: String,
},
activityLevel: {
type: String,
},
goals: {
type: String,
},
workoutPreferences: {
type: [String],
},
bmi: {
type: Number,
},
bodyFatPercentage: {
type: Number,
},
caloricIntake: {
type: Number,
},
createdAt: {
type: Date,
default: Date.now,
},
lastLogin: {
type: Date,
},
workoutHistory: {
type: [
{
date: Date,
workoutType: String,
duration: Number,
caloriesBurned: Number,
},
],
},
role: {
type: String,
default: "user",
},
settings: {
notifications: {
type: Boolean,
default: true,
},
theme: {
type: String,
default: "light",
},
},
});
export const User = mongoose.models.User ?? mongoose.model("User", userSchema);