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

Unify logout function over different places #1516

Merged
merged 1 commit into from
Nov 14, 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
12 changes: 12 additions & 0 deletions src/lib/helpers/logout.ts
Original file line number Diff line number Diff line change
@@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

await sdk.forConsole.account.deleteSession('current');
await invalidate(Dependencies.ACCOUNT);
trackEvent(Submit.AccountLogout);
await goto(`${base}/login`);
}
15 changes: 4 additions & 11 deletions src/lib/layout/header.svelte
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -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 &&
Expand Down
10 changes: 1 addition & 9 deletions src/routes/(console)/account/header.svelte
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -49,12 +47,6 @@
}
]
: permanentTabs;

async function logout() {
await sdk.forConsole.account.deleteSession('current');
trackEvent(Submit.AccountLogout);
await goto(`${base}/login`);
}
</script>

<Cover>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand All @@ -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');
}
Expand Down
Loading