@nuxtjs/auth
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -5,2 +5,17 @@ # Change Log | ||
<a name="3.4.0"></a> | ||
# [3.4.0](https://github.com/nuxt-community/auth-module/compare/v3.3.0...v3.4.0) (2017-12-29) | ||
### Bug Fixes | ||
* **store:** return promise in all actions ([1a9a76e](https://github.com/nuxt-community/auth-module/commit/1a9a76e)) | ||
### Features | ||
* improve compability for nuxt 1.0.0 ([7740dec](https://github.com/nuxt-community/auth-module/commit/7740dec)) | ||
<a name="3.3.0"></a> | ||
@@ -7,0 +22,0 @@ # [3.3.0](https://github.com/nuxt-community/auth-module/compare/v3.2.1...v3.3.0) (2017-12-28) |
import './auth.middleware' | ||
import authStore from './auth.store' | ||
export default async function ({ store, req, res }, inject) { | ||
export default async function (context, inject) { | ||
// Register auth store module | ||
store.registerModule('auth', authStore, { | ||
preserveState: !!store.state.auth, | ||
context.store.registerModule('auth', authStore, { | ||
preserveState: Boolean(context.store.state.auth), | ||
}) | ||
// Backward compability for Nuxt <= RC.11 | ||
if (!context.store.app) { | ||
context.store.app = { | ||
context | ||
} | ||
} | ||
// Fetch initial state | ||
await store.dispatch('auth/fetch', { req, res }) | ||
await context.store.dispatch('auth/fetch') | ||
} |
@@ -39,3 +39,3 @@ <% if (options.token.enabled && options.token.cookie) { %> | ||
// Update token | ||
updateToken ({ commit }, token) { | ||
async updateToken ({ commit }, token) { | ||
// Update token in store's state | ||
@@ -45,3 +45,3 @@ commit('SET_TOKEN', token) | ||
// Set Authorization token for all axios requests | ||
(this.$axios || this.app.$axios).setToken(token, '<%= options.token.type %>') | ||
this.$axios.setToken(token, '<%= options.token.type %>') | ||
@@ -79,3 +79,3 @@ <% if (options.token.localStorage) { %> | ||
} | ||
this.$res.setHeader('Set-Cookie', Cookie.serialize('<%= options.token.cookieName %>', token, params)) | ||
this.app.context.res.setHeader('Set-Cookie', Cookie.serialize('<%= options.token.cookieName %>', token, params)) | ||
} | ||
@@ -88,3 +88,3 @@ <% } %> | ||
// Fetch Token | ||
fetchToken ({ dispatch }) { | ||
async fetchToken ({ dispatch }) { | ||
let token | ||
@@ -102,3 +102,3 @@ | ||
if (!token) { | ||
const cookieStr = process.browser ? document.cookie : this.$req.headers.cookie | ||
const cookieStr = process.browser ? document.cookie : this.app.context.req.headers.cookie | ||
const cookies = Cookie.parse(cookieStr || '') || {} | ||
@@ -110,3 +110,3 @@ token = cookies['<%= options.token.cookieName %>'] | ||
if (token) { | ||
dispatch('updateToken', token) | ||
await dispatch('updateToken', token) | ||
} | ||
@@ -117,5 +117,5 @@ }, | ||
// Reset | ||
reset ({ dispatch, commit }) { | ||
async reset ({ dispatch, commit }) { | ||
<% if (options.user.enabled) { %>commit('SET_USER', null)<% } %> | ||
<% if (options.token.enabled) { %>dispatch('updateToken', null)<% } %> | ||
<% if (options.token.enabled) { %>await dispatch('updateToken', null)<% } %> | ||
}, | ||
@@ -125,10 +125,6 @@ | ||
// Fetch | ||
async fetch ({ getters, state, commit, dispatch }, { endpoint = '<%= options.user.endpoint %>', req, res } = {}) { | ||
// Backward compability for nuxt RCs which this.app.$ctx.req is not available | ||
this.$req = req | ||
this.$res = res | ||
async fetch ({ getters, state, commit, dispatch }, { endpoint = '<%= options.user.endpoint %>' } = {}) { | ||
<% if (options.token.enabled) { %> | ||
// Fetch and update latest token | ||
dispatch('fetchToken') | ||
await dispatch('fetchToken') | ||
@@ -143,3 +139,3 @@ // Skip if there is no token set | ||
try { | ||
const data = await (this.$axios || this.app.$axios).$<%= options.user.method.toLowerCase() %>(endpoint) | ||
const data = await this.$axios.$<%= options.user.method.toLowerCase() %>(endpoint) | ||
commit('SET_USER', data<%= options.user.propertyName ? ('[\'' + options.user.propertyName + '\']') : '' %>) | ||
@@ -150,3 +146,3 @@ } catch (e) { | ||
// Reset store | ||
dispatch('reset') | ||
await dispatch('reset') | ||
<% } %> | ||
@@ -160,6 +156,6 @@ } | ||
// Send credentials to API | ||
let data = await (this.$axios || this.app.$axios).$post(endpoint, fields) | ||
let data = await this.$axios.$post(endpoint, fields) | ||
<% if (options.token.enabled) { %> | ||
dispatch('updateToken', data['<%= options.token.name %>']) | ||
await dispatch('updateToken', data['<%= options.token.name %>']) | ||
<% } %> | ||
@@ -177,3 +173,3 @@ | ||
try { | ||
await (this.$axios || this.app.$axios).$<%= options.logout.method.toLowerCase() %>(endpoint) | ||
await this.$axios.$<%= options.logout.method.toLowerCase() %>(endpoint) | ||
} catch (e) { | ||
@@ -185,5 +181,5 @@ // eslint-disable-next-line no-console | ||
// Reset store | ||
dispatch('reset') | ||
await dispatch('reset') | ||
} | ||
} | ||
} |
{ | ||
"name": "@nuxtjs/auth", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Authentication module for Nuxt.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
17698
231