Skip to content

Commit

Permalink
Add option fetchUser
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestas-poskus committed Dec 23, 2017
1 parent 9d1f050 commit 6b4f4ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -28,7 +28,8 @@
user: {
endpoint: 'auth/user',
propertyName: 'user',
resetOnFail: true
resetOnFail: true,
fetchUser: true
},
login: {
endpoint: 'auth/login',
Expand Down Expand Up @@ -92,16 +93,16 @@ store.dispatch('auth/login', {
password: 'your_password'
}
})

// ... code ...
store.dispatch('auth/logout') // run logout

// ... code ...
store.state.auth.token // get access token

// ... code ...
store.state.auth.user // get user data

// ... code ...
store.getters['auth/loggedIn'] // get login status (true or false)
```
Expand Down
3 changes: 2 additions & 1 deletion lib/module.js
Expand Up @@ -7,7 +7,8 @@ module.exports = function (moduleOptions) {
user: {
endpoint: 'auth/user',
propertyName: 'user',
resetOnFail: true
resetOnFail: true,
fetchUser: true
},
login: {
endpoint: 'auth/login',
Expand Down
2 changes: 2 additions & 0 deletions lib/templates/auth.store.js
Expand Up @@ -146,7 +146,9 @@ export default {
<% } %>

// Fetch authenticated user
<% if (options.user.fetchUser) { %>
await dispatch('fetch')
<% } %>
},

// Logout
Expand Down

0 comments on commit 6b4f4ac

Please sign in to comment.