Skip to content
Permalink
Browse files

feat: 'authToken' option

  • Loading branch information...
ulivz committed Feb 7, 2019
1 parent 98cc5d1 commit e95319797d75826628ce397a803f29b4c3304e20
Showing with 9 additions and 3 deletions.
  1. +2 −1 lib/index.js
  2. +7 −2 lib/yuque.js
@@ -15,7 +15,7 @@ const debug = require('debug')(PACKAGE_NAME)
*/

module.exports = (opts, ctx) => {
let { repoId, repoUrl } = opts
let { repoId, repoUrl, authToken } = opts

if (repoId) {
assert(
@@ -54,6 +54,7 @@ module.exports = (opts, ctx) => {
}

Yuque.setRepoId(repoId)
Yuque.setAuthToken(authToken)
const yuque = Yuque.getInstance()

spinner.start(`Fetching repo detail ...`)
@@ -12,12 +12,17 @@ const isProduction = process.env.NODE_ENV === 'production'

let instance
let repoId
let authToken

module.exports = class Yuque {
static setRepoId(id) {
repoId = id
}

static setAuthToken(token) {
authToken = token
}

static getInstance() {
if (!instance) {
instance = new Yuque(repoId)
@@ -43,9 +48,9 @@ module.exports = class Yuque {

let response
const foptions = {}
if (AUTH_TOKEN) {
if (authToken || AUTH_TOKEN) {
foptions.headers = {
'X-Auth-Token': AUTH_TOKEN
'X-Auth-Token': authToken || AUTH_TOKEN
}
}

0 comments on commit e953197

Please sign in to comment.
You can’t perform that action at this time.