Extend built-in User model to support more properties and behaviors in loopback

本秂侑毒 提交于 2019-12-10 17:50:01

问题


I want a model to represent a profile in my loopback app. But, the built-in User model found in loopback only have the following properties

  • username
  • password
  • realm
  • emailVerified

What is the best way to extend the built-in User model in order to insert more properties like phone number, profile picture, and the likes?


回答1:


It was better if you have added your code for better answer according to your question but you can check this site which talks about customizing the built-in user model and also this. I hope this answers your question.




回答2:


Create a new model common/models/user.json

{
  "name": "user",
  "base": "User",
  "idInjection": true,
  "properties": {
      "firstName"{
         "type":"string",
         "required":true
       }
   }
  "restrictResetPasswordTokenScope": true,
  "emailVerificationRequired": true,
  "validations": [],
  "relations": {},
  "acls": [
    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "accessType": "READ",
      "permission": "ALLOW"
    }
  ],
  "methods": []
}

Add this to model-config.json

  "user":
    "dataSource": "yourDataSource"
  }

Hope this works for you



来源:https://stackoverflow.com/questions/47041731/extend-built-in-user-model-to-support-more-properties-and-behaviors-in-loopback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!