Our current situation:
We have an internal web app that I have built with express.js to store and analyze dna. We also have an 3rd party application that we use to store information related to experiments. Since this 3rd party application can also store dna, I have a function in my app to manually export dna information that can then be uploaded to this 3rd party software. Today I received the api keys for the 3rd party application and would like to update it's dna library when my colleagues enter dna into my app.
What we are looking to do:
The 3rd party app's api hands me a jwt token which I can then use to make requests in postman and have to update periodically as it expires. If I am doing this all server side in my app, how can I store the jwt access token as this will be used for every request that is made by the server? Is there a way to establish a global session in express?
f you need this token in only one js file, all you have to do is set the variable to the beginning of this file and you will refer to it. (global scope)
If in several files you have 2 options:
Ugly:
You are using the global
object eg:global.jwt1 = '...'
You create a token manager:
let tokens = {}
class Manager {
static get(name) {
if(!tokens[name])
return null;
return tokens[name]
}
static set(name, val) {
tokens[name] = val
}
}
module.exports = Manager;
And usage:
const jwt = require('./manager')
jwt.set('client 1', '...')
let t = jwt.get('client 1')