How to setToken with axios-module for multiple API's

samuells
0
samuells
commented a year ago

Hi,

I have 2 api, from which I need to get data. Both of them are using Bearer authentication token - but this token is different for each api. How can I set token to the axios, if I am using proxy to switch baseURL, but the token is set on the axios instance?

0
hqqxxf
0
hqqxxf
commented 10 months ago

I have the same question

0
yoann54
0
yoann54
commented 9 months ago

Hello,

Did u find a solution to this problem ? i have exactly the same and i don't find any docs on how to manage multiple api at the same time .

0
diegotejadav
0
diegotejadav
commented 7 months ago

@samuells @hqqxxf @yoann54, same question here, did some of you find any solution or example?

0
samuells
0
samuells
commented 6 months ago

No luck .. I didn't dig more on this.

0
llavre
5
llavre
commented 5 months ago

@samuells why did you don't create two axios instances?

In my case one for public and one for private apis.

0
samuells
0
samuells
commented 5 months ago

It was a long time ago … but I was trying achieve using nuxt settings file .. not sure anymore. Sorry

0
LTroya
0
LTroya
commented a month ago

@llavre how can you create two instances of $axios? axios has a create method for doing that

0
llavre
5
llavre
commented a month ago

@LTroya, not sure if I get your question right, but you should create two axios instances and then inject it in to context trough nuxt plugin or straight-forward prorotype in to Vue:

export default (ctx, inject) => {
  let privateAPI = axios.create({ baseURL: API_URL })
  Vue.prototype.$privateAPI = privateAPI
  ctx.privateAPI = privateAPI
  inject('privateAPI', privateAPI)
}

Then you can use it in your components and/or store.
https://nuxtjs.org/guide/plugins

1
Informations
QuestionUnresolved
#c3 - Created a year ago