User: Task: "Create Regiser Api for User"
    Description: "Generate a Node.js Regiser Api with with given dependenceis"
    Requirements:
    - Database: mongoose
    - Authentication: None specified
    - Output needed: Return only the function code as specified in dependencies
    - Dependencies: Create Register api function as exported function it's self. function mode :-  exports.functionname = async () =>{...}, 
Accept two parmas request and response, 
Accept two creidentional from User one email and passowrd, 
User cridentional should validated by joi, 
Api should build inder try catch method for error handeling., 
For hashing use bacrypt lirbary, 
Data should be saved in User database ., 
import the User Schema from this folder ../models/User.js as User , 
While registering you have to store all field in the refrencen User schema below given, 
Response should send back in Json formate with 'status' code of 200
    - Previous Code 
exports.registerUser = async (request, response) => {
    // Define validation schema using Joi
    const schema = Joi.object({
        email: Joi.string().email().required(),
        password: Joi.string().min(6).required()
    });

    try {
        // Validate request body against the schema
        const { error } = schema.validate(request.body);
        if (error) {
            return response.status(400).json({ status: 400, message: error.details[0].message });
        }

        const { email, password } = request.body;

        // Check if user already exists
        const existingUser = await User.findOne({ email });
        if (existingUser) {
            return response.status(400).json({ status: 400, message: 'User already exists' });
        }

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

        // Create new user
        const newUser = new User({
            email,
            password: hashedPassword
            // Add other User schema fields as necessary
        });

        // Save the user to the database
        await newUser.save();

        // Send success response
        response.status(200).json({ status: 200, message: 'User registered successfully' });
    } catch (err) {
        // Handle errors
        response.status(500).json({ status: 500, message: 'Internal Server Error' });
    }
};

exports.loginUser = async (request, response) => {
    // Define validation schema using Joi
    const schema = Joi.object({
        email: Joi.string().email().required(),
        password: Joi.string().min(6).required()
    });

    try {
        // Validate request body against the schema
        const { error } = schema.validate(request.body);
        if (error) {
            return response.status(400).json({ status: 400, message: error.details[0].message });
        }

        const { email, password } = request.body;

        // Check if user exists
        const existingUser = await User.findOne({ email });
        if (!existingUser) {
            return response.status(400).json({ status: 400, message: 'Invalid email or password' });
        }

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

        const client = redis.createClient();
        client.on('error', (err) => console.error('Redis Client Error', err));
        
        client.setex('logUser', 3600, JSON.stringify({ email: existingUser.email }));

        // Send success response
        response.status(200).json({ status: 200, message: 'Login successful' });
    } catch (err) {
        // Handle errors
        response.status(500).json({ status: 500, message: 'Internal Server Error' });
    }
};

    - Supporting data 
    - Updating File undefined
    
    Please generate the code for this task, following the instructions and including comments for clarity.
    While creating router for specifict file your have to read supporing file data and create for that 

    **Output Formats**: 

Return dependencies like this `const bcrypt = require('bcrypt');`  in this formate
```dependencies
const bcrypt = require('bcrypt');
```

Ensure this format is consistently followed in responses.
    
User: 


    
Assistant: