π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Improve logout system
Smaug67390cf288e575de
diff --git a/frontend/components/Sidebar/Sidebar.vue b/frontend/components/Sidebar/Sidebar.vueindex 35d4fb2a..fb01763d 100644--- a/frontend/components/Sidebar/Sidebar.vue+++ b/frontend/components/Sidebar/Sidebar.vue@@ -13,9 +13,12 @@<div class="user" v-if="userStore.user"><img :src="useAvatar(userStore.user)" alt="Avatar" style="width: 25px; height: 25px; border-radius: 50%" />- <div>- <div>{{ userStore.user.username }}</div>- <div class="email">{{ userStore.user.email }}</div>+ <div class="details">+ <div>+ <div>{{ userStore.user.username }}</div>+ <div class="email">{{ userStore.user.email }}</div>+ </div>+ <Icon name="logout" @click="logoutUser" class="logout" /></div></div><Search />@@ -45,14 +48,15 @@ const handleSearchShortCut = (e: KeyboardEvent) => {};if (import.meta.client && useUserStore().user?.role === 2) {- navigationItems.push({- id: 'manage-users',- type: 'default',- title: 'Manage users',- icon: 'users',- route: '/dashboard/admin/users',- childrens: [],- });+ if (navigationItems[navigationItems.length - 1]?.id !== 'manage-users')+ navigationItems.push({+ id: 'manage-users',+ type: 'default',+ title: 'Manage users',+ icon: 'users',+ route: '/dashboard/admin/users',+ childrens: [],+ });}const items = computed((): Item[] => {@@ -142,13 +146,26 @@ onBeforeUnmount(() => {display: flex;align-items: center;margin: 4px 0 0 5px;- div {+ .details {+ display: flex;+ justify-content: space-between;+ width: 100%;font-size: 0.85rem;margin-left: 5px;.email {font-size: 0.7rem;color: var(--font-color-light);}+ .logout {+ display: none;+ cursor: pointer;+ }+ }+ &:hover {+ .logout {+ display: block;+ opacity: 0.8;+ }}}</style>diff --git a/frontend/composables/icons.ts b/frontend/composables/icons.tsindex 4eb28c1f..0127f4c4 100644--- a/frontend/composables/icons.ts+++ b/frontend/composables/icons.ts@@ -15,7 +15,7 @@ const icons = {file: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--red);" d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>`,file_parent: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--green);" d="M320-320h200v-200H320v200Zm0-280h480v-200H320v200Zm280 280h200v-200H600v200Zm-280 80q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Z"/></svg>`,archive: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="none"><rect x="2.5" y="2.5" width="11" height="11" rx="1.5" fill="var(--grey-bg)" stroke="var(--grey)"/><rect x="6" y="4" width="2" height="2" rx="0.5" fill="var(--grey)"/><rect x="6" y="8" width="2" height="2" rx="0.5" fill="var(--grey)"/><rect x="8" y="10" width="2" height="2" rx="0.5" fill="var(--grey)"/><rect x="8" y="6" width="2" height="2" rx="0.5" fill="var(--grey)"/></svg>`,- logout: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h280v80H200Zm440-160-55-58 102-102H360v-80h327L585-622l55-58 200 200-200 200Z"/></svg>`,+ logout: `<svg xmlns="http://www.w3.org/2000/svg" style="fill:var(--font-color);" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h280v80H200Zm440-160-55-58 102-102H360v-80h327L585-622l55-58 200 200-200 200Z"/></svg>`,};export type IconName = keyof typeof icons;diff --git a/frontend/composables/user.ts b/frontend/composables/user.tsnew file mode 100644index 00000000..5e53d238--- /dev/null+++ b/frontend/composables/user.ts@@ -0,0 +1,33 @@+function logoutUser() {+ const store = useUserStore();+ store+ .logout()+ .then(() => {+ useNotifications().add({ title: 'Success:', message: 'Logged out', type: 'success', timeout: 3000 });+ setTimeout(() => {+ store.post_logout();+ useRouter().push('/login');+ }, 3000);+ })+ .catch(e => {+ useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });+ });+}++function logoutUserAll() {+ const store = useUserStore();+ store+ .logout_all()+ .then(() => {+ useNotifications().add({ title: 'Success:', message: 'Logged out', type: 'success', timeout: 3000 });+ setTimeout(() => {+ store.post_logout();+ useRouter().push('/login');+ }, 3000);+ })+ .catch(e => {+ useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });+ });+}++export { logoutUser, logoutUserAll };diff --git a/frontend/pages/dashboard/settings.vue b/frontend/pages/dashboard/settings.vueindex ebb8b8dc..2ce0296e 100644--- a/frontend/pages/dashboard/settings.vue+++ b/frontend/pages/dashboard/settings.vue@@ -18,7 +18,7 @@<NuxtLink to="/dashboard/categories"><Icon fill="var(--font-color)" name="categories" />Manage categories</NuxtLink><NuxtLink to="/dashboard/docs"><Icon fill="var(--font-color)" name="draft" />Manage documents</NuxtLink><span>Other</span>- <NuxtLink @click="logout"><Icon fill="var(--font-color)" name="logout" />Logout</NuxtLink>+ <NuxtLink @click="logoutUser"><Icon fill="var(--font-color)" name="logout" />Logout</NuxtLink></nav><div class="content"><button @click="close" class="close-btn"><Icon name="close" :big="true" /></button>@@ -88,8 +88,8 @@<AButton type="danger">Change password</AButton></form><h2>Danger</h2>- <AButton type="danger" @click="logout">Log out</AButton>- <AButton type="danger" @click="logout_all">Log out from all devices</AButton>+ <AButton type="danger" @click="logoutUser">Log out</AButton>+ <AButton type="danger" @click="logoutUserAll">Log out from all devices</AButton></div><div v-show="currentPage == 'backup'" class="page backup_page"><h1>Create a Database Backup</h1>@@ -180,35 +180,6 @@ async function submitFile() {}downloadLink.value = `${CDN}${result.result?.url || ''}`;}--function logout() {- store- .logout()- .then(() => {- useNotifications().add({ title: 'Success:', message: 'Logged out', type: 'success', timeout: 3000 });- setTimeout(() => {- store.post_logout();- router.push('/login');- }, 3000);- })- .catch(e => {- useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });- });-}-function logout_all() {- store- .logout_all()- .then(() => {- useNotifications().add({ title: 'Success:', message: 'Logged out from all devices', type: 'success', timeout: 3000 });- setTimeout(() => {- store.post_logout();- router.push('/login');- }, 3000);- })- .catch(e => {- useNotifications().add({ title: 'Error:', message: e, type: 'error', timeout: 3000 });- });-}</script><style scoped lang="scss">