Skip to content

Commit

Permalink
feat: add support for logging out without an API endpoint (#124)
Browse files Browse the repository at this point in the history
This is a fix for
https://nuxtjs.cmty.io/nuxt-community/auth-module/issues/c90

Setting the `logout` strategy to `false` will effectively mean that
logout does nothing (it simple returns).

However, when you have a stateless API, and no need to call
a logout endpoint, you still want the user to be logged out
in the browser (token removed, session reset, that sort of stuff).

This change handles that by not returning if the logout option
is falsy, but instead only skipping over the networking part.

I think this is the behaviour people would expect when they set
logout to `false`.
  • Loading branch information
joostdecock authored and pi0 committed Apr 6, 2018
1 parent 554a042 commit 6189c6d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/schemes/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ export default class LocalScheme {
}

async logout (endpoint) {
if (!this.options.endpoints.logout) {
return
// Only connect to logout endpoint if it's configured
if (this.options.endpoints.logout) {
await this.$auth
.requestWith(this.name, endpoint, this.options.endpoints.logout)
.catch(() => { })
}

await this.$auth
.requestWith(this.name, endpoint, this.options.endpoints.logout)
.catch(() => { })

// But logout locally regardless
if (this.options.tokenRequired) {
this._clearToken()
}
Expand Down

0 comments on commit 6189c6d

Please sign in to comment.