-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Some options changed and/or simplified
- Loading branch information
Pooya Parsa
committed
Nov 10, 2017
1 parent
869a4d1
commit 499c28a
Showing
4 changed files
with
123 additions
and
134 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
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 |
---|---|---|
|
@@ -4,37 +4,49 @@ const merge = require('lodash/merge') | |
module.exports = function (moduleOptions) { | ||
// Apply defaults | ||
const defaults = { | ||
user: { | ||
endpoint: 'auth/user', | ||
propertyName: 'user', | ||
}, | ||
login: { | ||
endpoint: 'auth/login', | ||
propertyName: 'token', | ||
session: false | ||
}, | ||
logout: { | ||
endpoint: 'auth/logout', | ||
method: 'GET', | ||
paramTokenName: '', | ||
appendToken: false | ||
}, | ||
user: { | ||
endpoint: 'auth/user', | ||
propertyName: 'user', | ||
paramTokenName: '', | ||
appendToken: false | ||
redirect: { | ||
notLoggedIn: '/login', | ||
loggedIn: '/' | ||
}, | ||
storageTokenName: 'nuxt-auth-token', | ||
tokenType: 'Bearer', | ||
notLoggedInRedirectTo: '/login', | ||
loggedInRedirectTo: '/' | ||
token: { | ||
enabled: true, | ||
name: 'token', | ||
cookieName: 'token', | ||
type: 'Bearer' | ||
} | ||
} | ||
|
||
const options = merge(defaults, moduleOptions, this.options.auth) | ||
|
||
// Plugin | ||
this.addPlugin({ src: resolve(__dirname, './templates/auth.plugin.js'), fileName: 'auth.plugin.js' }) | ||
this.addPlugin({ | ||
src: resolve(__dirname, './templates/auth.plugin.js'), | ||
fileName: 'auth.plugin.js', | ||
options | ||
}) | ||
|
||
// Middleware | ||
this.addTemplate({ src: resolve(__dirname, './templates/auth.middleware.js'), fileName: 'auth.middleware.js', options }) | ||
this.addTemplate({ | ||
src: resolve(__dirname, './templates/auth.middleware.js'), | ||
fileName: 'auth.middleware.js', | ||
options | ||
}) | ||
|
||
// Store | ||
this.addTemplate({ src: resolve(__dirname, './templates/auth.store.js'), fileName: 'auth.store.js', options }) | ||
this.addTemplate({ | ||
src: resolve(__dirname, './templates/auth.store.js'), | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pi0
Member
|
||
fileName: 'auth.store.js', | ||
options | ||
}) | ||
} |
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,17 +1,15 @@ | ||
import middleware from './middleware' | ||
|
||
const options = <%= serialize(options) %> | ||
|
||
middleware.auth = function authMiddleware ({ store, redirect }) { | ||
// If user not logged in, redirect to /login | ||
if (!store.getters['auth/loggedIn']) { | ||
return redirect(options.notLoggedInRedirectTo) | ||
return redirect('<%= options.redirect.loggedIn %>') | ||
} | ||
} | ||
|
||
middleware['no-auth'] = function noAuthMiddleware ({ store, redirect }) { | ||
// If user is already logged in, redirect to / | ||
if (store.getters['auth/loggedIn']) { | ||
return redirect(options.loggedInRedirectTo) | ||
return redirect('<%= options.redirect.notLoggedIn %>') | ||
} | ||
} |
Oops, something went wrong.
@pi0 , how does nuxt know that this file is a module in store?