1
votes

I am using Loopback. By default, it has a Users API. I am using postgres via loopback-connector-postgresql.

Following the first two pieces of code on this guide, I am able to create users but I can't figure out how to view the users.

Firstly, when I try to get all users under /explorer route. I am receiving 401 Authorization Required. I can't find my User data in my postgres db either. I checked all databases and tables and found nothing referring to User. Where are my users being persisted to?

I also modified model-config.json for User to see if I can get access:

"User": {
  "dataSource": "mydb",
  "public": true
}
...

but to no luck.

2

2 Answers

2
votes

Based on loopback docs you can specify where memory data must be stored in server/datasources.json like this:

  "db": {
    "name": "db",
    "connector": "memory",
    "file": "mydata.json"
  }

For more information you can read : https://docs.strongloop.com/display/public/LB/Memory+connector

Notic:

The memory connector is designed for development and testing of a single-process application without setting up a database. It cannot be used in a cluster as the worker processes will have their own isolated data not shared in the cluster. You can persist data between application restarts using the file property. See Data persistence for more information.

For view or manage users you must be create new model and extend it from loopback default User model then assign your postgresql connector for this model in server/model-config.json. next register new user then it will save in your postgresql database.

Or change User model dataSource to your postgresql in server/model-config.json like this:

 "User": {
    "dataSource": "MongoDB"
  }

Be aware changing this is observable after the first insert in the Users model.

see this project that you can learn how to config it.

0
votes

With your modification on model-config.json, Users are stored inside your database.

To get a list of all users remotely, you need to use the built-in User REST API.

There is a method GET users/ that could do what you are looking for, except permission is Deny by default.

Since, you cannot modify built-in REST API, you need to create a model myUser that extends User.

Then, using the strongloop command line, add and ACL to GRANT GET myUser endpoint to $everyone for instance.

For testing, you can grant access to $everyone but in production you should not allow users to retrieve a list of all the users in the database.