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

Fixed logout issues #429

Merged
merged 4 commits into from
Nov 18, 2024
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
18 changes: 15 additions & 3 deletions src/gui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ export default {
},
data: () => ({
visible: null,
isDark: true
isDark: true,
sseConnection: null,
}),
mixins: [AuthMixin],
methods: {
connectSSE() {
this.$sse(((typeof (process.env.VUE_APP_TARANIS_NG_CORE_SSE) == "undefined") ? "$VUE_APP_TARANIS_NG_CORE_SSE" : process.env.VUE_APP_TARANIS_NG_CORE_SSE) + "?jwt=" + this.$store.getters.getJWT, {format: 'json'})
.then(sse => {
this.sseConnection = sse
sse.onError(() => {
this.reconnectSSE()
});
sse.subscribe('news-items-updated', (data) => {
this.$root.$emit('news-items-updated', data)
});
Expand All @@ -50,7 +55,9 @@ export default {
sse.subscribe('report-item-unlocked', (data) => {
this.$root.$emit('report-item-unlocked', data)
});
});
}).catch(event => {
this.sseConnection = event.currentTarget
})
},
reconnectSSE() {
Expand Down Expand Up @@ -116,7 +123,12 @@ export default {
this.connectSSE()
});
}
},
beforeDestroy() {
if (this.sseConnection !== null) {
this.sseConnection.close()
}
}
};
</script>

Expand Down
159 changes: 79 additions & 80 deletions src/gui/src/components/UserMenu.vue
Original file line number Diff line number Diff line change
@@ -1,81 +1,80 @@
<template>
<div class="user-menu cx-user-menu">

<!--USERMENU-->
<v-menu close-on-click close-on-content-click offset-y st>
<template v-slot:activator="{ on }">
<div class="user-menu-button pl-0 pr-2">
<v-btn icon v-on="on">
<v-icon color="white" medium>mdi-shield-account</v-icon>
</v-btn>
</div>
</template>
<v-list>
<v-list-item>
<v-list-item-avatar class="">
<v-icon>mdi-shield-account</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ username }}</v-list-item-title>
<v-list-item-subtitle>{{ organizationName }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-divider></v-divider>

<v-list-item @click="settings">
<v-list-item-icon>
<v-icon>mdi-cog-outline</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title> {{ $t('user_menu.settings') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-list-item @click="logout">
<v-list-item-icon>
<v-icon>mdi-logout</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title> {{ $t('user_menu.logout') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>

<UserSettings/>

</div>
</template>

<script>
import UserSettings from "./UserSettings";

export default {
name: "UserMenu",
components: {
UserSettings
},
data: () => ({
darkTheme: false
}),
computed: {
username() {
return this.$store.getters.getUserName
},
organizationName() {
return this.$store.getters.getOrganizationName
}
},
methods: {
logout() {
this.$store.dispatch('logout');
},
settings() {
this.$root.$emit('show-user-settings');
},
darkToggle() {
this.$vuetify.theme.dark = this.darkTheme
}
}
}
<template>
<div class="user-menu cx-user-menu">

<!--USERMENU-->
<v-menu close-on-click close-on-content-click offset-y st>
<template v-slot:activator="{ on }">
<div class="user-menu-button pl-0 pr-2">
<v-btn icon v-on="on">
<v-icon color="white" medium>mdi-shield-account</v-icon>
</v-btn>
</div>
</template>
<v-list>
<v-list-item>
<v-list-item-avatar class="">
<v-icon>mdi-shield-account</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>{{ username }}</v-list-item-title>
<v-list-item-subtitle>{{ organizationName }}</v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
<v-divider></v-divider>

<v-list-item @click="settings">
<v-list-item-icon>
<v-icon>mdi-cog-outline</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title> {{ $t('user_menu.settings') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>

<v-list-item @click="logout">
<v-list-item-icon>
<v-icon>mdi-logout</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title> {{ $t('user_menu.logout') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>

<UserSettings/>

</div>
</template>

<script>
import AuthMixin from "@/services/auth/auth_mixin";
import UserSettings from "./UserSettings";

export default {
name: "UserMenu",
mixins: [AuthMixin],
components: {
UserSettings
},
data: () => ({
darkTheme: false
}),
computed: {
username() {
return this.$store.getters.getUserName
},
organizationName() {
return this.$store.getters.getOrganizationName
}
},
methods: {
settings() {
this.$root.$emit('show-user-settings');
},
darkToggle() {
this.$vuetify.theme.dark = this.darkTheme
}
}
}
</script>
10 changes: 10 additions & 0 deletions src/gui/src/services/auth/auth_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ var AuthMixin = {
}),

methods: {
logout() {
this.$store.dispatch('logout').then(() => {
if (this.$store.getters.hasExternalLogoutUrl) {
window.location = this.$store.getters.getLogoutURL;
} else {
window.location.reload();
}
})
},

isAuthenticated() {
return AuthService.isAuthenticated()
},
Expand Down
Loading