@Ghadban125's answer is correct, though I'd like to add some more details.
Not only do you need to overwrite the callback function in ./node_modules/@strapi/plugin-users-permissions/server/controllers/auth.js. You'd also need to register your new function in your strapi-server.js (the one that you create under the src directory, not the one under node_modules, similar to how you overwrite the callback function) which looks like this:
const { callback } = require("./controllers/Auth.js");
const utils = require("@strapi/utils");
const { ApplicationError } = utils.errors;
module.exports = (plugin) => {
plugin.controllers.auth.callback = async (ctx) => {
try {
await callback(ctx);
// ctx.send(result);
} catch (error) {
throw new ApplicationError(error.message);
}
};
}
You'll also need to differentiate the request's identifier between an email, username, or phone number. To do this, you'll need to edit your ./src/extensions/users-permissions/controllers/auth.js file:
/* left out for brevity */
const phoneNumberRegExp = /^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/;
/* left out for brevity */
module.exports = {
async callback(ctx) {
/* left out for brevity */
const query = { provider };
// Check if the provided identifier is an email or not.
const isEmail = emailRegExp.test(params.identifier);
// Check if the provided identifier is a phone number or not.
const isPhoneNumber = phoneNumberRegExp.test(params.identifier);
// Set the identifier to the appropriate query field.
if (isEmail) {
query.email = params.identifier.toLowerCase();
} else if (isPhoneNumber) {
query.phoneNumber = params.identifier;
} else {
query.username = params.identifier;
}
/* left out for brevity */
},
};