registration doesn't work anymore

Registration error: Error: User validation failed: desiredPhysique: Path `desiredPhysique` is required., email: Path `email` is required.
    at ValidationError.inspect (D:\apps\Fitness-app\backend\node_modules\mongoose\lib\error\validation.js:52:26)
    at formatValue (node:internal/util/inspect:805:19)
    at inspect (node:internal/util/inspect:364:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2279:40)
    at formatWithOptions (node:internal/util/inspect:2141:10)
    at console.value (node:internal/console/constructor:352:14)
    at console.warn (node:internal/console/constructor:385:61)
    at register (D:\apps\Fitness-app\backend\controllers\authController.js:64:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  errors: {
    desiredPhysique: ValidatorError: Path `desiredPhysique` is required.
        at validate (D:\apps\Fitness-app\backend\node_modules\mongoose\lib\schemaType.js:1385:13)
        at SchemaType.doValidate (D:\apps\Fitness-app\backend\node_modules\mongoose\lib\schemaType.js:1369:7)
        at D:\apps\Fitness-app\backend\node_modules\mongoose\lib\document.js:3071:18
        at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
      properties: [Object],
      kind: 'required',
      path: 'desiredPhysique',
      value: undefined,
      reason: undefined,
      [Symbol(mongoose#validatorError)]: true
    },
    email: ValidatorError: Path `email` is required.
        at validate (D:\apps\Fitness-app\backend\node_modules\mongoose\lib\schemaType.js:1385:13)
        at SchemaType.doValidate (D:\apps\Fitness-app\backend\node_modules\mongoose\lib\schemaType.js:1369:7)
        at D:\apps\Fitness-app\backend\node_modules\mongoose\lib\document.js:3071:18
        at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
      properties: [Object],
      kind: 'required',
      path: 'email',
      value: undefined,
      reason: undefined,
      [Symbol(mongoose#validatorError)]: true
    }
  },
  _message: 'User validation failed'
}

frontend error message:
 ERROR  Registration Error: [AxiosError: Request failed with status code 500]
 ERROR  Backend URL: 10.0.0.203:5000
 ERROR  Error Response: {"message": "Server error"}

// controllers/authController.js

const jwt = require('jsonwebtoken');
const User = require('../models/User'); // Adjust the path as necessary

// Function to generate JWT
const generateToken = (userId) => {
    return jwt.sign(
        { userId },
        process.env.JWT_SECRET, // Ensure this matches the secret in auth.js
        { expiresIn: '1h' }      // Token validity duration
    );
};

// Login Function
const login = async (req, res) => {
    const { username, password } = req.body;

    try {
        // Find user by username
        const user = await User.findOne({ username });
        if (!user) {
            return res.status(400).json({ message: 'Invalid credentials' });
        }

        // Check if password matches
        const isMatch = await user.comparePassword(password); // Implement comparePassword in your User model
        if (!isMatch) {
            return res.status(400).json({ message: 'Invalid credentials' });
        }

        // Generate token
        const token = generateToken(user._id);

        // Return token to client
        res.json({ token });
    } catch (err) {
        console.error('Login error:', err);
        res.status(500).json({ message: 'Server error' });
    }
};

// Register Function (Optional)
const register = async (req, res) => {
    const { username, password } = req.body;

    try {
        // Check if user already exists
        let user = await User.findOne({ username });
        if (user) {
            return res.status(400).json({ message: 'User already exists' });
        }

        // Create new user
        user = new User({ username, password });
        await user.save();

        // Generate token
        const token = generateToken(user._id);

        // Return token to client
        res.json({ token });
    } catch (err) {
        console.error('Registration error:', err);
        res.status(500).json({ message: 'Server error' });
    }
};

module.exports = { login, register };


const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');

const UserSchema = new mongoose.Schema({
    username: { type: String, required: true, unique: true },
    email:    { type: String, required: true, unique: true },
    password: { type: String, required: true },
    role: { type: String, enum: ['user', 'admin'], default: 'user' }, // Added role field
    desiredPhysique: { type: String, enum: ['lean', 'muscular', 'athletic'], required: true },
    fitnessGoals: [String], // e.g., ['strength', 'endurance']
    dietaryPreferences: [String],
    dietaryRestrictions: [String],
}, { timestamps: true });

// Password hashing middleware
UserSchema.pre('save', async function(next) {
    if (!this.isModified('password')) return next();
    try {
        const salt = await bcrypt.genSalt(10);
        this.password = await bcrypt.hash(this.password, salt);
        next();
    } catch(err) {
        next(err);
    }
});

// Password comparison method
UserSchema.methods.comparePassword = function(candidatePassword) {
    return bcrypt.compare(candidatePassword, this.password);
}

module.exports = mongoose.model('User', UserSchema);

.env
PORT=5000
MONGO_URI=mongodb+srv://ketex11565:<PRESIDIO_ANONYMIZED_EMAIL_ADDRESS>/
JWT_SECRET=your_jwt_secret_key
BACKEND_URL=10.0.0.203:5000

// server.js
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');

const app = express();

// Middleware
app.use(express.json());

// CORS Configuration
app.use(cors({
    origin: '*',
    methods: ['GET', 'POST', 'PUT', 'DELETE'],
    credentials: true,
}));

// Connect to MongoDB
mongoose.connect(process.env.MONGO_URI, {
    // Removed deprecated options as per earlier advice
})
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));

// Routes
app.get('/', (req, res) => {
    res.send('Fitness App Backend');
});

const authRoutes = require('./routes/auth');
app.use('/api/auth', authRoutes);

const exerciseRoutes = require('./routes/exercises');
app.use('/api/exercises', exerciseRoutes);

const progressRoutes = require('./routes/progress');
app.use('/api/progress', progressRoutes);

// Start Server
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
    console.log(`Server running on port ${PORT}`);
});