potato4d / nuxt-basic-auth-module

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

How can I access this auth with axios? #3

Closed davision closed 6 years ago

davision commented 6 years ago

How can I access this auth with axios in a form of headers and Base64?

potato4d commented 6 years ago

@davision

See below.

global

import axios from 'axios'
const b64string = 'YOUR_B64_STRING'

axios.defaults.headers.authorization = `Basic ${b64string}`

axios.get('http://localhost:3000/')

local

import axios from 'axios'
const b64string = 'YOUR_B64_STRING'

axios.get(
  'http://localhost:3000/',
  {
    headers: {
      authorization: `Basic ${b64string}`
    }
  }
)
davision commented 6 years ago

Thank you very much! Will try this out.