quicksln / LiteDB.Identity

ASP.NET Core Identity provider for LiteDB database engine.
MIT License
26 stars 7 forks source link

Can't edit nor delete users with LiteDbIdentity the same way I do with Microsoft's Identity #8

Closed DanielRodFT closed 9 months ago

DanielRodFT commented 9 months ago

When trying to update or delete a user, the user passed to my controller's UpdateUser method doesn't have an ID, the id property is null. I'm using the same exact process with Microsoft own Identity and the ID does return. I don't know if theres something I'm doing wrong of updating doesn't work the same as with microsoft's identity. The object does exist in the database and has a working Id.

  1. User object passed to update method when Microsoft's identity (first picture):

image

  1. Select query with the required Id:

image

quicksln commented 9 months ago

Hello @DanielRodFT

One more time thank you for using LiteDb.Identity :)

I have just verified this, and it is functioning as expected. After creating the user, a new ID is returned to the user instance. To be doubly sure, I have created a new unit test for it. Please refer to the screenshots below.

s1

s2a

Based on your screenshot, I assume this is a POST action for updating a user from an MVC form submission. Could you please double-check whether you are correctly storing the user.Id on the form after creation?

Please see pseudo code below :

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post))
{
    @Html.AntiForgeryToken()

    @Html.HiddenFor(model => model.UserId)

    ...
}

Regards Piotr

DanielRodFT commented 9 months ago

Thank you for your help. As you mentioned it was due to the MVC model binder not being able to recreate the Id from the url. I'm now able to edit and delete users. Thanks:)