dj-rest-auth icon indicating copy to clipboard operation
dj-rest-auth copied to clipboard

Problem with update user model endpoint when using PUT method

Open oussama-he opened this issue 3 years ago • 7 comments

I'm trying to use this package to implement authentication in my project. However, I'm facing a problem with /dj-rest-auth/user/ endpoint, and there is no enough documentation. When I try to use this endpoint with PUT method with first_name and last_name I get this error:

{
    "username": [
        "This field is required."
    ]
}

And when I add the username I get this error

{
    "username": [
        "A user with that username already exists."
    ]
}

Can anyone tell me how can I fix this? Thank you in advance.

oussama-he avatar Dec 08 '20 11:12 oussama-he

I would also love to know the answer to this! I think it's because PUT needs a username but to update you want to hit PATCH

xanderbailey avatar Mar 01 '21 23:03 xanderbailey

I am seeing this same error even with PATCH any ideas? I only started seeing this when i moved from djangl-rest-auth to dj-rest-auth

jmbowman1107 avatar Jul 26 '21 20:07 jmbowman1107

I'm having the same issue. I'm using the (current) latest stable versions:

  • dj-rest-auth: v2.2.3
  • django-allauth: v0.47.0

Although I wasn't able to use the PUT /dj-rest-auth/user endpoint (passing username, first_name, and last_name), I was able to use the PATCH endpoint while omitting the username (passing only the first_name and last_name).

grimzy avatar Feb 14 '22 06:02 grimzy

Same problem. Btw, there is no test for PUT method on user_details endpoint, only GET and PATCH: https://github.com/iMerica/dj-rest-auth/blob/f5079fef6a953d1fcf658b627a08265a62454ac0/dj_rest_auth/tests/test_api.py#L409-L423

spirkaa avatar Apr 18 '22 11:04 spirkaa

I've also encountered the same problem with PATCH /dj-rest-auth/user/ with contents of username, first_name, and last_name. However, I was able to PATCH the first_name and last_name without passing username as @grimzy said.

Is there any further information or solution about this?

devappmin avatar Feb 01 '23 15:02 devappmin

I guess this is because the pk is kinda related username cohesively. I had this problem and found a solution, which is ok as far.

use PUT when the username changes, also include the pk in payload. use PATCH when the username doesn't, and exclude pk and username in payload.

      const result =
        state.username === userStore.username
          ? await doPatchUserDetail(payloadPatch)
          : await doPutUserDetail(payloadPut);

doublo7 avatar May 27 '23 09:05 doublo7

Hi there trying to update user details with no success, like curl -X PATCH 127.0.0.1:8000/dj-rest-auth/user/ -H "Authorization: Token 8eaf1f90a6c71e4f3e8b441372f9c29d6b6ef98f" -d first_name="artemggg" -d last_name="artemggg" and it returns always {"pk":17,"email":"[email protected]","first_name":null,"last_name":null}% also tryed PUT with same result can some one say what i do wrong please

art3mHQ avatar Sep 02 '23 07:09 art3mHQ