Unify logout function over different places

This commit is contained in:
ernstmul
2024-11-14 09:44:30 +01:00
parent c197f15f8b
commit a217153d31
4 changed files with 20 additions and 24 deletions
+12
View File
@@ -0,0 +1,12 @@
import { sdk } from '$lib/stores/sdk';
import { goto, invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { base } from '$app/paths';
export async function logout() {
await sdk.forConsole.account.deleteSession('current');
await invalidate(Dependencies.ACCOUNT);
trackEvent(Submit.AccountLogout);
await goto(`${base}/login`);
}
+4 -11
View File
@@ -1,12 +1,12 @@
<script lang="ts">
import { goto, invalidate } from '$app/navigation';
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { AvatarInitials, DropList, DropListItem, DropListLink, Support } from '$lib/components';
import { app } from '$lib/stores/app';
import { user } from '$lib/stores/user';
import { organizationList, organization, newOrgModal } from '$lib/stores/organization';
import { page } from '$app/stores';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { trackEvent } from '$lib/actions/analytics';
import { tooltip } from '$lib/actions/tooltip';
import { toggleCommandCenter } from '$lib/commandCenter/commandCenter.svelte';
import Button from '$lib/elements/forms/button.svelte';
@@ -18,10 +18,10 @@
import SystemMode from '$lib/images/mode/system-mode.svg';
import { feedback } from '$lib/stores/feedback';
import { slide } from 'svelte/transition';
import { sdk } from '$lib/stores/sdk';
import { isCloud } from '$lib/system';
import { Feedback } from '$lib/components/feedback';
import { BillingPlan, Dependencies } from '$lib/constants';
import { BillingPlan } from '$lib/constants';
import { logout } from '$lib/helpers/logout';
import { upgradeURL } from '$lib/stores/billing';
let showDropdown = false;
@@ -36,13 +36,6 @@
}
}
async function logout() {
await sdk.forConsole.account.deleteSession('current');
await invalidate(Dependencies.ACCOUNT);
trackEvent(Submit.AccountLogout);
await goto(`${base}/login`);
}
function onBlur(event: MouseEvent) {
if (
showDropdown &&
+1 -9
View File
@@ -1,13 +1,11 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackEvent } from '$lib/actions/analytics';
import { Tab, Tabs } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { isTabSelected } from '$lib/helpers/load';
import { Cover, CoverTitle } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { logout } from '$lib/helpers/logout';
import { user } from '$lib/stores/user';
import { isCloud } from '$lib/system';
@@ -49,12 +47,6 @@
}
]
: permanentTabs;
async function logout() {
await sdk.forConsole.account.deleteSession('current');
trackEvent(Submit.AccountLogout);
await goto(`${base}/login`);
}
</script>
<Cover>
@@ -1,6 +1,5 @@
<script lang="ts">
import { base } from '$app/paths';
import { goto, invalidate } from '$app/navigation';
import { invalidate } from '$app/navigation';
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
@@ -13,6 +12,7 @@
import { checkForUsageLimit } from '$lib/stores/billing';
import { isCloud } from '$lib/system';
import { organization } from '$lib/stores/organization';
import { logout } from '$lib/helpers/logout';
const dispatch = createEventDispatcher();
@@ -24,8 +24,7 @@
await sdk.forConsole.teams.deleteMembership(selectedMember.teamId, selectedMember.$id);
if (isUser) {
await sdk.forConsole.account.deleteSession('current');
await goto(`${base}/login`);
logout();
} else {
dispatch('deleted');
}