@nuxtjs/auth
Advanced tools
Comparing version 4.8.5 to 4.9.0
@@ -5,2 +5,18 @@ # Changelog | ||
## [4.9.0](https://github.com/nuxt-community/auth-module/compare/v4.8.5...v4.9.0) (2020-03-15) | ||
### Features | ||
* **core:** return response from `loginWith` ([#541](https://github.com/nuxt-community/auth-module/issues/541)) ([7e4f1ed](https://github.com/nuxt-community/auth-module/commit/7e4f1edebde7938428a80154c1fefc2fa24ff9ce)), closes [#144](https://github.com/nuxt-community/auth-module/issues/144) [#411](https://github.com/nuxt-community/auth-module/issues/411) [#249](https://github.com/nuxt-community/auth-module/issues/249) | ||
* **local scheme:** add `autoFetchUser` option ([#543](https://github.com/nuxt-community/auth-module/issues/543)) ([344920c](https://github.com/nuxt-community/auth-module/commit/344920c0c2d90a6db6265eb286f42f64d1da6ac7)) | ||
### Bug Fixes | ||
* clear tokens when calling `$auth.reset()` ([#544](https://github.com/nuxt-community/auth-module/issues/544)) ([ab75ebc](https://github.com/nuxt-community/auth-module/commit/ab75ebcd54d45c79d060b810cfd2ba90fd5738ac)), closes [#172](https://github.com/nuxt-community/auth-module/issues/172) | ||
* fix `setUserToken` issues ([#528](https://github.com/nuxt-community/auth-module/issues/528)) ([02d14ac](https://github.com/nuxt-community/auth-module/commit/02d14ac5695c5797e290ce9494d0c0451fbf5296)), closes [#278](https://github.com/nuxt-community/auth-module/issues/278) | ||
* remove the trailing slash of paths in `isSameURL` ([#542](https://github.com/nuxt-community/auth-module/issues/542)) ([fb63f6f](https://github.com/nuxt-community/auth-module/commit/fb63f6f6dc17a7afa0b3a51d4b8f447de2ede7de)) | ||
* **module:** don't log fatal error when vuex is disabled ([#518](https://github.com/nuxt-community/auth-module/issues/518)) ([59831fb](https://github.com/nuxt-community/auth-module/commit/59831fbee852ce38598a405f6cc1b971c0430339)) | ||
### [4.8.5](https://github.com/nuxt-community/auth-module/compare/v4.8.4...v4.8.5) (2019-12-27) | ||
@@ -7,0 +23,0 @@ |
@@ -131,6 +131,7 @@ import Storage from './storage' | ||
return this.wrapLogin(this.strategy.login(...arguments)).catch(error => { | ||
this.callOnError(error, { method: 'login' }) | ||
return Promise.reject(error) | ||
}) | ||
return this.wrapLogin(this.strategy.login(...arguments)) | ||
.catch(error => { | ||
this.callOnError(error, { method: 'login' }) | ||
return Promise.reject(error) | ||
}) | ||
} | ||
@@ -263,3 +264,3 @@ | ||
request (endpoint, defaults) { | ||
request (endpoint, defaults, withResponse) { | ||
const _endpoint = | ||
@@ -279,6 +280,11 @@ typeof defaults === 'object' | ||
.then(response => { | ||
if (_endpoint.propertyName) { | ||
return getProp(response.data, _endpoint.propertyName) | ||
const result = _endpoint.propertyName ? getProp(response.data, _endpoint.propertyName) : response.data | ||
if (withResponse) { | ||
return { | ||
response, | ||
result | ||
} | ||
} else { | ||
return response.data | ||
return result | ||
} | ||
@@ -295,3 +301,3 @@ }) | ||
requestWith (strategy, endpoint, defaults) { | ||
requestWith (strategy, endpoint, defaults, withResponse) { | ||
const token = this.getToken(strategy) | ||
@@ -309,3 +315,3 @@ | ||
return this.request(_endpoint) | ||
return this.request(_endpoint, false, withResponse) | ||
} | ||
@@ -318,4 +324,5 @@ | ||
return Promise.resolve(promise) | ||
.then(() => { | ||
.then(response => { | ||
this.$storage.setState('busy', false) | ||
return response | ||
}) | ||
@@ -322,0 +329,0 @@ .catch(error => { |
export const isUnset = o => typeof o === 'undefined' || o === null | ||
export const isSet = o => !isUnset(o) | ||
export const isSameURL = (a, b) => a.split('?')[0] === b.split('?')[0] | ||
export const isSameURL = (a, b) => a.split('?')[0].replace(/\/+$/, '') === b.split('?')[0].replace(/\/+$/, '') | ||
@@ -6,0 +6,0 @@ export const isRelativeURL = u => |
@@ -54,3 +54,3 @@ const { resolve, join, basename } = require('path') | ||
// Enforce vuex store because auth depends on it | ||
if (!this.options.store) { | ||
if (options.vuex && !this.options.store) { | ||
logger.fatal('Enable vuex store by creating `store/index.js`.') | ||
@@ -57,0 +57,0 @@ } |
@@ -38,7 +38,8 @@ export default class LocalScheme { | ||
// Ditch any leftover local tokens before attempting to log in | ||
await this._logoutLocally() | ||
await this.$auth.reset() | ||
const result = await this.$auth.request( | ||
const { response, result } = await this.$auth.request( | ||
endpoint, | ||
this.options.endpoints.login | ||
this.options.endpoints.login, | ||
true | ||
) | ||
@@ -55,18 +56,16 @@ | ||
return this.fetchUser() | ||
if (this.options.autoFetchUser) { | ||
await this.fetchUser() | ||
} | ||
return response | ||
} | ||
async setUserToken (tokenValue) { | ||
// Ditch any leftover local tokens before attempting to log in | ||
await this._logoutLocally() | ||
const token = this.options.tokenType | ||
? this.options.tokenType + ' ' + tokenValue | ||
: tokenValue | ||
this.$auth.setToken(this.name, token) | ||
this._setToken(token) | ||
if (this.options.tokenRequired) { | ||
const token = this.options.tokenType | ||
? this.options.tokenType + ' ' + tokenValue | ||
: tokenValue | ||
this.$auth.setToken(this.name, token) | ||
this._setToken(token) | ||
} | ||
return this.fetchUser() | ||
@@ -104,7 +103,7 @@ } | ||
// But logout locally regardless | ||
return this._logoutLocally() | ||
// But reset regardless | ||
return this.$auth.reset() | ||
} | ||
async _logoutLocally () { | ||
async reset () { | ||
if (this.options.tokenRequired) { | ||
@@ -114,3 +113,7 @@ this._clearToken() | ||
return this.$auth.reset() | ||
this.$auth.setUser(false) | ||
this.$auth.setToken(this.name, false) | ||
this.$auth.setRefreshToken(this.name, false) | ||
return Promise.resolve() | ||
} | ||
@@ -123,3 +126,4 @@ } | ||
globalToken: true, | ||
tokenName: 'Authorization' | ||
tokenName: 'Authorization', | ||
autoFetchUser: true | ||
} |
@@ -8,3 +8,5 @@ import { encodeQuery, parseQuery } from '../utilities' | ||
response_type: 'token', | ||
tokenName: 'Authorization' | ||
tokenName: 'Authorization', | ||
token_key: 'access_token', | ||
refresh_token_key: 'refresh_token' | ||
} | ||
@@ -71,5 +73,10 @@ | ||
async logout () { | ||
async reset () { | ||
this._clearToken() | ||
return this.$auth.reset() | ||
this.$auth.setUser(false) | ||
this.$auth.setToken(this.name, false) | ||
this.$auth.setRefreshToken(this.name, false) | ||
return Promise.resolve() | ||
} | ||
@@ -141,5 +148,5 @@ | ||
// accessToken/idToken | ||
let token = parsedQuery[this.options.token_key || 'access_token'] | ||
let token = parsedQuery[this.options.token_key] | ||
// refresh token | ||
let refreshToken = parsedQuery[this.options.refresh_token_key || 'refresh_token'] | ||
let refreshToken = parsedQuery[this.options.refresh_token_key] | ||
@@ -169,8 +176,8 @@ // Validate state | ||
if (data.access_token) { | ||
token = data.access_token | ||
if (data[this.options.token_key]) { | ||
token = data[this.options.token_key] | ||
} | ||
if (data.refresh_token) { | ||
refreshToken = data.refresh_token | ||
if (data[this.options.refresh_token_key]) { | ||
refreshToken = data[this.options.refresh_token_key] | ||
} | ||
@@ -177,0 +184,0 @@ } |
{ | ||
"name": "@nuxtjs/auth", | ||
"version": "4.8.5", | ||
"version": "4.9.0", | ||
"description": "Authentication module for Nuxt.js", | ||
@@ -44,5 +44,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@nuxtjs/axios": "^5.9.0", | ||
"@nuxtjs/axios": "^5.9.5", | ||
"body-parser": "^1.19.0", | ||
"consola": "^2.11.2", | ||
"consola": "^2.11.3", | ||
"cookie": "^0.4.0", | ||
@@ -52,29 +52,29 @@ "is-https": "^1.0.0", | ||
"lodash": "^4.17.15", | ||
"nanoid": "^2.1.8" | ||
"nanoid": "^2.1.11" | ||
}, | ||
"devDependencies": { | ||
"@nuxtjs/toast": "^3.3.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.5", | ||
"bootstrap-vue": "^2.1.0", | ||
"codecov": "^3.6.1", | ||
"cookie-parser": "^1.4.4", | ||
"eslint": "^6.8.0", | ||
"eslint-config-standard": "^14.1.0", | ||
"eslint-plugin-import": "^2.19.1", | ||
"eslint-plugin-jest": "^23.1.1", | ||
"eslint-plugin-node": "^11.0.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"eslint-plugin-vue": "^6.1.1", | ||
"express": "^4.17.1", | ||
"express-jwt": "^5.3.1", | ||
"jest": "^24.9.0", | ||
"jsdom": "^15.2.1", | ||
"lodash.get": "^4.4.2", | ||
"nuxt-class-component": "^1.3.0", | ||
"nuxt-edge": "^2.11.1-26290089.0cb2df73", | ||
"puppeteer": "^2.0.0", | ||
"standard-version": "^7.0.1" | ||
"@nuxtjs/toast": "latest", | ||
"babel-plugin-transform-class-properties": "latest", | ||
"babel-plugin-transform-decorators-legacy": "latest", | ||
"bootstrap-vue": "latest", | ||
"codecov": "latest", | ||
"cookie-parser": "latest", | ||
"eslint": "latest", | ||
"eslint-config-standard": "latest", | ||
"eslint-plugin-import": "latest", | ||
"eslint-plugin-jest": "latest", | ||
"eslint-plugin-node": "latest", | ||
"eslint-plugin-promise": "latest", | ||
"eslint-plugin-standard": "latest", | ||
"eslint-plugin-vue": "latest", | ||
"express": "latest", | ||
"express-jwt": "latest", | ||
"jest": "latest", | ||
"jsdom": "latest", | ||
"lodash.get": "latest", | ||
"nuxt-class-component": "latest", | ||
"nuxt-edge": "latest", | ||
"puppeteer": "latest", | ||
"standard-version": "latest" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72064
1286
Updated@nuxtjs/axios@^5.9.5
Updatedconsola@^2.11.3
Updatednanoid@^2.1.11