Allow loopback application to use previous access token

倾然丶 夕夏残阳落幕 提交于 2019-12-07 20:16:59

问题


In my loopback application, once i create the access token (after login), it remains valid in my application unless application stops. when application restarted it is not allowing previous access token. How can i make previous access token validate even after restarting the application?


回答1:


Your access token is getting stored by default in loopback memory. Therefore, it persists only until the application is restarted.

open server/model-config.json

"AccessToken": {
    "dataSource": "db",
    "public": false
  }

This is the initial configuration of the Access Tokens. See here the storage datasource is db which is loopback memory. You need to change this to your MongoDB or some other storage

You need to store Access Tokens in the database rather in the memory.

For example lets store this to the mongoDb storage.

  1. Assuming you already have mongodb installed in your system. Install the mongodb connector. In console type

    npm install loopback-connector-mongodb

  2. Now configure the server/datasources.json file. Add this line to this file.

    "mongodb": { "host": "0.0.0.0", "port": 27017, "database": "MONGODB DATABASE NAME", "password": "MONGODB PASSWORD", "name": "MONGODB NAME", "connector": "mongodb", "user": "YOUR USER NAME" }

  3. Open server/model-config.json. change this db to mongodb

    "AccessToken": { "dataSource": "mongodb", "public": false }

Now run the loopback server `Acces Tokens will be there even after restarting the application.



来源:https://stackoverflow.com/questions/33841085/allow-loopback-application-to-use-previous-access-token

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