Hello,
I try to verify recaptcha before register but i can’t override users-permissions,
Thanks for any suggestions !
Hello,
I try to verify recaptcha before register but i can’t override users-permissions,
Thanks for any suggestions !
Maybe you can extend users-permissions like this: https://smoothdvd.medium.com/add-a-customize-users-permissions-provider-for-strapi-v4-6aa78c642977
Thank you !
I find an easy way to verify captcha:
src/extensions/users-permissions/strapi-server.js
const axios = require("axios");
module.exports = (plugin) => {
const register = plugin.controllers.auth.register;
plugin.controllers.auth.register = async (ctx) => {
ctx.request.body.confirmed = false;
const token = ctx.request.body.token;
const gres = await axios.post(
`https://www.google.com/recaptcha/api/siteverify?secret=${process.env.GOOGLE_SITEKEY}&response=${token}`
);
console.log(gres.data);
if (!gres.data.success) {
return ctx.badRequest(
null,
formatError({
id: "Auth.form.error.token.provide",
message: "Please provide a valid token.",
})
);
}
await register(ctx);
};
return plugin;
};
Great work!
Thanks so much, I was breaking my head over this!
One detail, it’s obviously the secret you have to pass in to the url , not the sitekey as you have it
Sorry, but I couldn’t see something effect in my app.
I used Strapi with typescript and create strapi-server.js file like you
@Nguyen_Nguyen If you use typescript, try using strapi-server.ts
Also try to remove the cache and dist folder
Also try to build the project again
At the last resource, try pulling the new source code and try modify the extension, you will see it work in the new source code and try comparing with your current one
Hope this help!