User registration doesn't work

I have an issue with registering/adding new users and I cannot find a way to resolve it.

When registering a new user through the API call /auth/local/register (with Postman) I get the following response always, even thought there is no other User with the same username (as there is only one user so far):

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": [
        {
            "messages": [
                {
                    "id": "Auth.form.error.username.taken",
                    "message": "Username already taken"
                }
            ]
        }
    ],
    "data": [
        {
            "messages": [
                {
                    "id": "Auth.form.error.username.taken",
                    "message": "Username already taken"
                }
            ]
        }
    ]
}

This happens no matter what I put as a username. So far I had only two users anyway and I can make sure that the username is not used.

On the console log I get: debug POST /auth/local/register (796 ms) 400

When trying to use the admin panel to add a new User and try to save the user-data. I get the the following “SERVER ERROR” message and I stay in the same window:

On the User content-type I have added a few fields name: text, surname: text, office: enum and I registered the first two users.

Then I added a few more fields bio: text, photo: media and I cannot register anyone anymore. This fields are not required.

After creating the first two users I have added relations to other content types and I might have deleted a few relations to/from other content types.

So I cannot register, neither from the admin panel nor from the REST API.

Is this only from the admin panel or also from REST/GraphQL?

I tried both the admin panel and the REST API with Postman and it doesn’t work.

(I also edited the question to make it more clear)

I tried to install from scratch my repo on a new server (and created the database (DB) and everything that is required).

The registrations there work fine from what I see. So the problem might be related with the DB (I am using MySQL).

Another issue that I have on the main server that I am using, is that the ctx.state.user is always empty, even though the user is authenticated. Again I was using Postman to:

  1. Login and get the JWT token.
  2. Make a PUT request to update the user profile.

But there was no ctx.state.user.

On the “new” server that I started, both user registration and user updating works.

Could the problem be something with the database?

We had this issue too. The error we got back was identical to yours even though we had NO identical user in the database.
The issue was that we had a set one of our User fields to “required”. To fix, we edited the field to NOT be “required”, and then we could register users without issue.

1 Like

For people who also had this problem,
my problem was I was sending fake email when testing register ex: “hteshtest@gmail.com”, try to use a real existing one, cause I think it has to do with sendmail “strapi built-in email provider” probably if it could not send to the fake destination, the response will be 400 Bad request

1 Like

The problem is because the confirmation email setting in true but without an email-provider set up. so you need to turn off the confirmation email in the advanced setting.

1 Like

Exactly this, the error message isn’t helpful (but we are working on that) but this is 99% of the time the problem.