potato4d / nuxt-basic-auth-module

Provide basic auth your Nuxt.js application
https://www.npmjs.com/package/nuxt-basic-auth-module
MIT License
310 stars 9 forks source link

Module breaks subsequent axios requests using Basic Auth credentials from .env #63

Closed robinscholz closed 3 years ago

robinscholz commented 5 years ago

When installing this module axios requests subsequent to the login get sent with the wrong credentials. Instead of using credentials stored within an .env file, the requests get sent with the credentials that where used for the basic-auth dialogue.

const auth = {
  username: process.env.kirbyEmail,
  password: process.env.kirbyAuth
}

async getPages({ commit }, locale) {
    try {
      const pages = await this.$axios.$get(baseURL + '/rest/site/children', {
        auth,
        headers: { 'x-language': locale },
        params: { select: 'content, id, children, status, template' }
      })
      return commit('setPages', pages)
    } catch (error) {
      console.error(error)
    }
  }

async nuxtServerInit({ dispatch, state }) {
    const locale = state.i18n.locale
    await dispatch('getPages', locale)
  }

Any idea how this could be fixed?

potato4d commented 3 years ago

@robinscholz Thank you for your report. Can you provide the minimum URL of Codesandbox that can reproduce the phenomenon?