You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My app needs an authentication token to request an API.
This token must be included in the header of each request (except the authentication request). Because it can expire my application must be able to request a new one (and must therefore remove the old one from the headers to do it)
So, is it possible to modify the options declared with the default() method ? Or must I store my token in a varriable and include the header in each request ?
Thanks in advance
An example of what I need
constrp=require('request-promise').defaults({uri: "myUrl",method: 'POST',headers: {'x-app': 'myApp',},});// manage (define, modify, ...) the header tokenfunctionlogin(){constoptions={body: {'a specific body Object'}};// if exists, delete the current token from headersif(rp.defaults.headers['my-token'])deleterp.defaults.headers['my-token'];returnrp(options).then(result=>{// add the new token in the defaults headersrp.defaults.headers['my-token']=result.token// something else});}// token is in defaults optionsfunctionanotherFunction(){constoptions={body: {'an other body Object'}};returnrp(options).then(result=>{// do something else});}
The text was updated successfully, but these errors were encountered:
Hi,
My app needs an authentication token to request an API.
This token must be included in the header of each request (except the authentication request). Because it can expire my application must be able to request a new one (and must therefore remove the old one from the headers to do it)
So, is it possible to modify the options declared with the
default()
method ? Or must I store my token in a varriable and include the header in each request ?Thanks in advance
An example of what I need
The text was updated successfully, but these errors were encountered: