问题
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.
Assuming you already have mongodb installed in your system. Install the mongodb connector. In console type
npm install loopback-connector-mongodb
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" }
Open
server/model-config.json
. change thisdb
tomongodb
"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