How to extend auth controller in v4!?

const axios = require("axios");
module.exports = {
  async index(ctx) {
    const { body } = ctx.request;
    const hostname = "localhost";
    const absoluteURL = `<http://${hostname}:${strapi.config.server.port}`;>
    const sanitizeOutput = (user) => {
      const {
        password,
        resetPasswordToken,
        confirmationToken,
        ...sanitizedUser
      } = user;
      return sanitizedUser;
    };
    try {
      let { data } = await axios.post(`${absoluteURL}/api/auth/local`, body);
      const populatedUser = await strapi.entityService.findOne(
        "plugin::users-permissions.user",
        data.user.id,
        {
          populate: {
            role: {
              fields: ["type"],
            },
          },
        }
      );
      data.user = sanitizeOutput(populatedUser);
      if (data && data.jwt) {
        ctx.cookies.set("jwt", data.jwt, {
          httpOnly: true,
          secure: false,
          maxAge: 1000 * 60 * 60 * 24 * 14, // 14 Day Age
        });
      }
    } catch (error) {
      // handle error
    }
  },
};

Please note that this is a basic example and you might need to adjust it according to your needs.

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: