Unable to authenticate if deleted record exist in database

I have two records with same email in database, as per my understandings soft deleted records are not considered while making auth.attempt(email, password call. However I am unable to authenticate, where one records in marked as is_deleted to true and updated timestamps in deleted_at other with null in deleted_at and is_deleted with false

1 Like

Are you using some package for soft deletes or wrote it yourself, since AdonisJS doesn’t support soft deletes out of box

I am using nothing, I was assuming that Adonis supports soft delete. Can you guide how do add a Trait or global scopes or something similar which give that functionality, I don’t want to use soft-delete package available on git this time I need to add my own implementation as I have two fields to validate, in my case is_deleted is primary for that purpose, however soft delete prefer deleted_at

There’s some example how to make and use traits in documentation: https://adonisjs.com/docs/4.1/traits

Other than that I think you could read some existing package like this: https://github.com/radmen/adonis-lucid-soft-deletes (first form search)

And then fork it or do something similar based on your needs

1 Like

this is going to give my expected result … taken from a adonis forum thread

adding following in Model boot function

this.addGlobalScope(function (builder) {

      builder.where('is_deleted', 0)