Search code examples
strongloop

Removing unused elements in user model


In Strongloop, I want to extend the user model, but there are some fields I don't need:

username
credentials
verificationToken

When I create my database, I do not want to create columns for these useless fields. What is the best way around this?


Solution

  • Right now, there is an open issue: A better way for customizing built-in models

    If you still want it: the work around is to first update the /node_modules/loopback/common/models/user.json, deleting the not required fields as:

    {
      "name": "User",
      "properties": {
        "realm": {
          "type": "string"
        },
        "password": {
          "type": "string",
          "required": true
        },
        "email": {
          "type": "string",
          "required": true
        },
        "emailVerified": "boolean",
        "status": "string",
        "created": "date",
        "lastUpdated": "date"
      },
      "hidden": ["password"],
      "acls": [
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "DENY"
        },
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "ALLOW",
          "property": "create"
        },
        {
          "principalType": "ROLE",
          "principalId": "$owner",
          "permission": "ALLOW",
          "property": "deleteById"
        },
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "ALLOW",
          "property": "login"
        },
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "ALLOW",
          "property": "logout"
        },
        {
          "principalType": "ROLE",
          "principalId": "$owner",
          "permission": "ALLOW",
          "property": "findById"
        },
        {
          "principalType": "ROLE",
          "principalId": "$owner",
          "permission": "ALLOW",
          "property": "updateAttributes"
        },
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "ALLOW",
          "property": "confirm"
        },
        {
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "ALLOW",
          "property": "resetPassword",
          "accessType": "EXECUTE"
        }
      ],
      "relations": {
        "accessTokens": {
          "type": "hasMany",
          "model": "AccessToken",
          "foreignKey": "userId",
          "options": {
            "disableInclude": true
          }
        }
      }
    }
    

    Note: I have also deleted challenges as it is now deprecated.

    Then you can extend it. For sql databases, you can create corresponding tables as in the model.json