Enhance the functionality of the Security Provider

Please expand the usefulness of the Security Provider

With the aid Claude Sonnet the 4th, I managed to expand the usefulness of the Security Provider from this structure:

{
  "name": "secUsers",
  "module": "auth",
  "action": "provider",
  "options": {
    "secret": "TwMIMu2aNErKWEZ",
    "provider": "Database",
    "connection": "db",
    "users": {
      "table": "users",
      "identity": "UserID",
      "username": "UserEmail",
      "password": "UserPassword"
    },
    "permissions": {}
  },
  "meta": [
    {
      "name": "identity",
      "type": "text"
    }
  ]
}

to this structure:

{
  "name": "security",
  "module": "auth",
  "action": "provider",
  "options": {
    "secret": "BOLYLicauGzLLt4",
    "provider": "Database",
    "connection": "inductease",
    "passwordVerify": true,
    "users": {
      "table": "employee_login_view",
      "identity": "credential_id",
      "username": "email",
      "password": "password_hash",
      "identityFields": [
        "credential_id",
        "employee_id", 
        "company_id",
        "first_name",
        "last_name",
        "role",
        "induction_status",
        "position",
        "department_id",
        "is_active",
        "email"
      ]
    },
    "permissions": {}
  },
  "meta": [
    {
      "name": "identity",
      "type": "object",
      "sub": [
        {"name": "credential_id", "type": "number"},
        {"name": "employee_id", "type": "number"},
        {"name": "company_id", "type": "number"},
        {"name": "first_name", "type": "text"},
        {"name": "last_name", "type": "text"},
        {"name": "role", "type": "text"},
        {"name": "induction_status", "type": "text"},
        {"name": "position", "type": "text"},
        {"name": "department_id", "type": "number"},
        {"name": "is_active", "type": "boolean"},
        {"name": "email", "type": "text"}
      ]
    }
  ]
}

The benefit from the expanded Security Provider

  1. Direct access to the data
  2. No separate (employee) lookup needed
  3. Better performance due to a single database query
1 Like

To add a bit of momentum to this request, I have a users table that includes the associated company ID. In the past, using Wappler's UI, I have first called the users table to fetch the company ID to then fetch the associated company.

Having to develop a much larger project and having to repeat this process for multiple server actions, I now handcode the following for the company (licensee) ID:

identity.company_id

as in:

It would be a great time saver to have this facilitated in the UI.

This is somewhat similar to the Model concept in MVC frameworks such as Laravel.

I'm actually surprised I haven't opened a feature request for that.

And then you could access stuff like:
$user→company→licenses

They should take a look at AdonisJS and Laravel and port some stuff over

It would be very handy for building SaaS applications where maximum data is related to company. I’m creating an app for my future project. Where I've to add a single query after login step to get the company id and with that company id I fetch data of that company in which that user is working.

I hope I’m having right approach to do this. :neutral_face:

1 Like

Exactly!