Search code examples
javascriptnode.jsreactjsstrapi

Strapi register method not allowed 405 in v4 seems url is incorrect


quite puzzled with a Strapi question. Working with v4 and hooking up a registration functionality. Invoke code is below. All other things are good i.e. function variables being submitted, etc. But when I call strapi.register I get a 405 All my roles/permissions are good:

// make request to register user with strapi
const response = await strapi.register(username, email, password);

Result: POST http://localhost:1337/auth/local/register 405 (Method Not Allowed)

When I look in the Strapi admin in the User roles and permissions, I see in the box where the register options is that the target url is: /api/auth/local/register !!!

What gives? I read that you may can do something in /config/api.js or similar, or maybe use a proxy in package.json. Can't resolve why this url is different? Is it a bug? How would you make this work. I am specultating that I need to add /api to the request somewhere. But don't know where. Thanks everyone!


Solution

  • You're missing the api/ part. You should change your path for :

      POST  http://localhost:1337/api/auth/local/register