hey can you make it so that the user can signup using email or username and it should automatically detect and login 
"""
// controllers/authController.js

const { z } = require('zod');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const User = require('../models/User');
const monitorService = require('../services/monitorService');
const logger = require('../utils/logger');

// Zod Schemas
const signupSchema = z.object({
    username: z.string().min(3).max(30),
    email: z.string().email(),
    password: z.string().min(6),
    listOfUrls: z.array(z.string().url()).optional(),
    timePeriod: z.enum(['30s', '1m', '3m', '5m', '10m', '1h']).optional(),
    emailSend: z.boolean().optional(),
    phoneNo: z.string().optional(),
});

const loginSchema = z.object({
    email: z.string().email(),
    password: z.string().min(6),
});

exports.signup = async (req, res) => {
    try {
        // Validate input
        const parsedData = signupSchema.parse(req.body);

        // Check if user exists
        const existingUser = await User.findOne({ $or: [{ email: parsedData.email }, { username: parsedData.username }] });
        if (existingUser) {
            return res.status(400).json({ message: 'Username or Email already exists' });
        }

        // Hash password
        const hashedPassword = await bcrypt.hash(parsedData.password, 10);

        // Create user
        const user = new User({
            username: parsedData.username,
            email: parsedData.email,
            password: hashedPassword,
            listOfUrls: parsedData.listOfUrls || [],
            timePeriod: parsedData.timePeriod || '1m',
            emailSend: parsedData.emailSend || false,
            phoneNo: parsedData.phoneNo || '',
        });

        await user.save();

        // Start monitoring for the new user
        monitorService.startMonitoring(user);

        // Generate JWT
        const token = jwt.sign(
            { id: user._id, username: user.username, email: user.email },
            process.env.JWT_SECRET
        );

        res.status(201).json({ message: 'User registered successfully', token });
    } catch (error) {
        if (error instanceof z.ZodError) {
            return res.status(400).json({ errors: error.errors });
        }
        logger.error('Signup Error:', error);
        res.status(500).json({ message: 'Server Error' });
    }
};

exports.login = async (req, res) => {
    try {
        // Validate input
        const parsedData = loginSchema.parse(req.body);

        // Find user
        const user = await User.findOne({ email: parsedData.email });
        if (!user) {
            return res.status(400).json({ message: 'Invalid email or password' });
        }

        // Compare passwords
        const isMatch = await bcrypt.compare(parsedData.password, user.password);
        if (!isMatch) {
            return res.status(400).json({ message: 'Invalid email or password' });
        }

        // Generate JWT
        const token = jwt.sign(
            { id: user._id, username: user.username, email: user.email },
            process.env.JWT_SECRET,
            { expiresIn: '1h' }
        );

        res.status(200).json({ message: 'Logged in successfully', token });
    } catch (error) {
        if (error instanceof z.ZodError) {
            return res.status(400).json({ errors: error.errors });
        }
        logger.error('Login Error:', error);
        res.status(500).json({ message: 'Server Error' });
    }
};
"""
"""
// models/User.js

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
    username: { type: String, required: true, unique: true, minlength: 3, maxlength: 30 },
    email: { type: String, required: true, unique: true, maxlength: 100 },
    password: { type: String, required: true, minlength: 6 },
    listOfUrls: { type: [String], default: [] },
    timePeriod: { 
        type: String, 
        enum: ['30s', '1m', '3m', '5m', '10m', '1h'], 
        default: '1m' 
    },
    emailSend: { type: Boolean, default: false },
    phoneNo: { type: String, default: '' },
}, { timestamps: true });

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