Skip to content

Commit 6189c6d

Browse files
joostdecockpi0
authored andcommitted
feat: add support for logging out without an API endpoint (#124)
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`.
1 parent 554a042 commit 6189c6d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/schemes/local.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ export default class LocalScheme {
7373
}
7474

7575
async logout (endpoint) {
76-
if (!this.options.endpoints.logout) {
77-
return
76+
// Only connect to logout endpoint if it's configured
77+
if (this.options.endpoints.logout) {
78+
await this.$auth
79+
.requestWith(this.name, endpoint, this.options.endpoints.logout)
80+
.catch(() => { })
7881
}
7982

80-
await this.$auth
81-
.requestWith(this.name, endpoint, this.options.endpoints.logout)
82-
.catch(() => { })
83-
83+
// But logout locally regardless
8484
if (this.options.tokenRequired) {
8585
this._clearToken()
8686
}

0 commit comments

Comments
 (0)