Skip to content

Commit

Permalink
feat: add resetOnError (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishitatsuyuki authored and pi0 committed Jun 2, 2018
1 parent 2df6a64 commit 469f2f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ See [Extending Auth Plugin](recipes/extend.md)

* Default: `false`

If enabled, user will be automatically logged out if any error happens. (For example when token expired)
Either a boolean or a function is accepted. If a function is passed, it will take the same arguments as `onError` handlers and return `Boolean` to inform whether a reset should be performed.

If enabled, user will be automatically logged out if an error happens. (For example when token expired)

### `rewriteRedirects`

Expand Down
9 changes: 9 additions & 0 deletions lib/core/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export default class Auth {
}

async init () {
// Reset on error
if (this.options.resetOnError) {
this.onError((...args) => {
if (typeof (this.options.resetOnError) !== 'function' || this.options.resetOnError(...args)) {
this.reset()
}
})
}

// Restore strategy
this.$storage.syncUniversal('strategy', this.options.defaultStrategy)

Expand Down

0 comments on commit 469f2f8

Please sign in to comment.