User: Task: "Create Router for APIs"
    Description: "Generate router code that includes POST method endpoints for each given API"
    Requirements:
    - Database: mongoose
    - Authentication: None specified
    - Output needed: Return only the function code as specified in dependencies
    - Dependencies: Import the express module using `const express = require('express');`, 
Import the controller file from `../controllers/authController.js` and assign it to `taskCntl`, 
Initialize the router using `const router = express.Router();`, 
For each API endpoint name provided in the supporting data, create a POST route in the form `router.post('/endpoint', taskCntl.apiName) `, 
Read each API name from the supporting data and dynamically create a route for each, 
For deleteTask api have id params in the route as in this form `router.post('/endpoint/:taskId', authCtl.apiName)`, 
Export the router using `module.exports = router;` at the end
    - Previous Code 
const router = express.Router();

// API names from supporting data
const apiNames = ['registerUser', 'loginUser', 'deleteTask'];

// Dynamically creating routes for each API endpoint
apiNames.forEach(apiName => {
    if (apiName === 'deleteTask') {
        router.post(`/${apiName}/:taskId`, taskCntl[apiName]);
    } else {
        router.post(`/${apiName}`, taskCntl[apiName]);
    }
});

module.exports = router;

    - Supporting data 
// 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();
redisClient.on('error', (err) => console.log('Redis Client Error', err));

// Login API 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().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;

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

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

        // Store user in Redis cache
        redisClient.set('logUser', email, 'EX', 3600); // Expires in 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' });
    }
};

    - 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: