-
Notifications
You must be signed in to change notification settings - Fork 927
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: more compability for nuxt@next
- Loading branch information
Pooya Parsa
committed
Dec 28, 2017
1 parent
994152b
commit d50be11
Showing
2 changed files
with
13 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,12 @@ | ||
import './auth.middleware' | ||
import authStore from './auth.store' | ||
|
||
export default async function (ctx, inject) { | ||
const { store } = ctx | ||
|
||
// Inject $ctx | ||
inject('ctx', ctx) | ||
|
||
export default async function ({ store, req, res }, inject) { | ||
// Register auth store module | ||
store.registerModule('auth', authStore, { | ||
preserveState: !!store.state.auth, | ||
}) | ||
|
||
// Fetch initial state | ||
try { | ||
await store.dispatch('auth/fetch') | ||
} catch (e) { | ||
// Not authorized | ||
// Check axios module is correctly registered | ||
if (!ctx.$axios) { | ||
/* eslint-disable no-console */ | ||
console.error('[@nuxtjs/auth]', 'Please make sure @nuxtjs/axios is added after this module!') | ||
} | ||
} | ||
await store.dispatch('auth/fetch', { req, res }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters