Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back resetOnError #197

Merged
merged 1 commit into from
Jun 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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