User: Task: "Create Login Api for User"
    Description: "Generate a Node.js Login Api with with given dependenceis"
    Requirements:
    - Database: mongoose
    - Authentication: None specified
    - Output needed: Return only the function code as specified in dependencies
    - Dependencies: Create login 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 compare passwords use bacrypt lirbary, , 
Data should be saved in User database., 
Use redis caching to store logged users. Storing key `logUser`, 
Response should send back in Json formate with 'status' code of 200
    - Previous Code 
// Define the function as specified
exports.registerUser = async (req, res) => {
    try {
        // Define the schema for validation with Joi
        const schema = Joi.object({
            email: Joi.string().email().required(),
            password: Joi.string().min(6).required()
        });

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

        // Extract user credentials from the request body
        const { email, password } = req.body;

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

        // Hash the user's password
        const salt = await bcrypt.genSalt(10);
        const hashedPassword = await bcrypt.hash(password, salt);

        // Create a new user instance and save it to the database
        user = new User({ email, password: hashedPassword });
        await user.save();

        // Return a successful response
        res.status(200).json({ status: 200, message: 'User registered successfully' });

    } catch (err) {
        // Error handling
        res.status(500).json({ status: 500, message: 'Internal Server Error' });
    }
};

// Create a Redis client
const redisClient = redis.createClient();


// Export the login function
exports.loginUser = async (req, res) => {
    try {
        // Define the schema for validation with Joi
        const schema = Joi.object({
            email: Joi.string().email().required(),
            password: Joi.string().required()
        });

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

        // Extract user credentials from the request body
        const { email, password } = req.body;

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

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

        // Cache the logged user in Redis
        redisClient.setex('logUser', 3600, JSON.stringify(user)); // Storing with a timeout of 1 hour

        // Return a successful response
        res.status(200).json({ status: 200, message: 'Login successful' });

    } catch (err) {
        // Error handling
        res.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: