Permalink
Browse files

feat: handle endpoints.propertyName

closes #46.
  • Loading branch information...
pi0 committed Feb 1, 2018
1 parent ae9cca9 commit 710561bfc9c6a7537e7c52993cb6d1a12578f8b0
Showing with 14 additions and 9 deletions.
  1. +9 −9 lib/auth.js
  2. +1 −0 package.json
  3. +4 −0 yarn.lock
@@ -1,5 +1,6 @@
import Cookie from 'cookie'
import Cookies from 'js-cookie'
import getProp from 'dotprop'
import Vue from 'vue'
export default class Auth {
@@ -185,16 +186,15 @@ export default class Auth {
}
async _request (name, endpoint) {
const defaults = this.options.endpoints[name]
if (!defaults) {
if (!this.options.endpoints[name]) {
return
}
const opts = Object.assign({}, this.options.endpoints[name], endpoint)
try {
const { data } = await this.$axios.request(
Object.assign({}, defaults, endpoint)
)
return data
const { data } = await this.$axios.request(opts)
return opts.propertyName ? getProp(data, opts.propertyName) : data
} catch (err) {
this._onError({ name, err, endpoint })
}
@@ -207,10 +207,10 @@ export default class Auth {
}
// Extract and set token
this.setToken(data.token)
this.setToken(data)
// Fetch User
if (this.options.fetchUserOnLogin) {
if (this.options.fetchUserOnLogin && this.options.endpoints.user) {
return this.fetchUser()
}
@@ -228,7 +228,7 @@ export default class Auth {
return
}
this.setState('user', data.user)
this.setState('user', data)
this.setState('loggedIn', true)
}
@@ -36,6 +36,7 @@
"dependencies": {
"@nuxtjs/axios": "^5.0.0-rc.2",
"cookie": "^0.3.1",
"dotprop": "^1.0.2",
"js-cookie": "^2.2.0",
"lodash": "^4.17.4"
},

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 710561b

Please sign in to comment.