fix: keep org store after logout
This fix tackled a bug where if I logged out, go to org landing page, open a course and enrol then it gets redirected to a 404 page because `$currentOrg.siteName` is undefined.
This commit is contained in:
@@ -1,44 +1,20 @@
|
||||
<script>
|
||||
import { globalStore } from '$lib/utils/store/app';
|
||||
import { user, profile, defaultProfileState, defaultUserState } from '$lib/utils/store/user';
|
||||
import {
|
||||
currentOrg,
|
||||
orgs,
|
||||
defaultCurrentOrgState,
|
||||
currentOrgDomain,
|
||||
currentOrgPath
|
||||
} from '$lib/utils/store/org';
|
||||
import { profile } from '$lib/utils/store/user';
|
||||
import { currentOrg, currentOrgDomain, currentOrgPath } from '$lib/utils/store/org';
|
||||
import { ChevronDown, Settings } from 'carbon-icons-svelte';
|
||||
import Avatar from '$lib/components/Avatar/index.svelte';
|
||||
import TextChip from '$lib/components/Chip/Text.svelte';
|
||||
import Logout from 'carbon-icons-svelte/lib/Logout.svelte';
|
||||
import Rocket from 'carbon-icons-svelte/lib/Rocket.svelte';
|
||||
import NewTab from 'carbon-icons-svelte/lib/NewTab.svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { profileMenu } from '../store';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import { capturePosthogEvent } from '$lib/utils/services/posthog';
|
||||
import { t } from '$lib/utils/functions/translations';
|
||||
import posthog from 'posthog-js';
|
||||
|
||||
async function logout() {
|
||||
const { error } = await supabase.auth.signOut();
|
||||
|
||||
if (error) {
|
||||
console.error('Error logging out: ', error);
|
||||
}
|
||||
|
||||
currentOrg.set(defaultCurrentOrgState);
|
||||
orgs.set([]);
|
||||
user.set(defaultUserState);
|
||||
profile.set(defaultProfileState);
|
||||
|
||||
capturePosthogEvent('user_logged_out');
|
||||
posthog.reset();
|
||||
import { logout } from '$lib/utils/functions/logout';
|
||||
|
||||
async function handleLogout() {
|
||||
await logout();
|
||||
closeMenu();
|
||||
|
||||
goto('/login');
|
||||
}
|
||||
|
||||
function closeMenu() {
|
||||
@@ -168,7 +144,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button on:click={logout} class="w-full space-y-4 pt-3">
|
||||
<button on:click={handleLogout} class="w-full space-y-4 pt-3">
|
||||
<span class="flex items-center gap-2">
|
||||
<Logout />
|
||||
<p class="text-sm font-semibold">{$t('settings.profile.logout')}</p>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import posthog from 'posthog-js';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import { capturePosthogEvent } from '$lib/utils/services/posthog';
|
||||
import { currentOrg, orgs, defaultCurrentOrgState } from '$lib/utils/store/org';
|
||||
import { user, profile, defaultProfileState, defaultUserState } from '$lib/utils/store/user';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
@@ -12,8 +11,6 @@ export async function logout(redirect = true) {
|
||||
console.error('Error logging out: ', error);
|
||||
}
|
||||
|
||||
currentOrg.set(defaultCurrentOrgState);
|
||||
orgs.set([]);
|
||||
user.set(defaultUserState);
|
||||
profile.set(defaultProfileState);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user