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>
|
<script>
|
||||||
import { globalStore } from '$lib/utils/store/app';
|
import { globalStore } from '$lib/utils/store/app';
|
||||||
import { user, profile, defaultProfileState, defaultUserState } from '$lib/utils/store/user';
|
import { profile } from '$lib/utils/store/user';
|
||||||
import {
|
import { currentOrg, currentOrgDomain, currentOrgPath } from '$lib/utils/store/org';
|
||||||
currentOrg,
|
|
||||||
orgs,
|
|
||||||
defaultCurrentOrgState,
|
|
||||||
currentOrgDomain,
|
|
||||||
currentOrgPath
|
|
||||||
} from '$lib/utils/store/org';
|
|
||||||
import { ChevronDown, Settings } from 'carbon-icons-svelte';
|
import { ChevronDown, Settings } from 'carbon-icons-svelte';
|
||||||
import Avatar from '$lib/components/Avatar/index.svelte';
|
import Avatar from '$lib/components/Avatar/index.svelte';
|
||||||
import TextChip from '$lib/components/Chip/Text.svelte';
|
import TextChip from '$lib/components/Chip/Text.svelte';
|
||||||
import Logout from 'carbon-icons-svelte/lib/Logout.svelte';
|
import Logout from 'carbon-icons-svelte/lib/Logout.svelte';
|
||||||
import Rocket from 'carbon-icons-svelte/lib/Rocket.svelte';
|
import Rocket from 'carbon-icons-svelte/lib/Rocket.svelte';
|
||||||
import NewTab from 'carbon-icons-svelte/lib/NewTab.svelte';
|
import NewTab from 'carbon-icons-svelte/lib/NewTab.svelte';
|
||||||
import { goto } from '$app/navigation';
|
|
||||||
import { profileMenu } from '../store';
|
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 { t } from '$lib/utils/functions/translations';
|
||||||
import posthog from 'posthog-js';
|
import { logout } from '$lib/utils/functions/logout';
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
|
async function handleLogout() {
|
||||||
|
await logout();
|
||||||
closeMenu();
|
closeMenu();
|
||||||
|
|
||||||
goto('/login');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeMenu() {
|
function closeMenu() {
|
||||||
@@ -168,7 +144,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/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">
|
<span class="flex items-center gap-2">
|
||||||
<Logout />
|
<Logout />
|
||||||
<p class="text-sm font-semibold">{$t('settings.profile.logout')}</p>
|
<p class="text-sm font-semibold">{$t('settings.profile.logout')}</p>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import posthog from 'posthog-js';
|
import posthog from 'posthog-js';
|
||||||
import { supabase } from '$lib/utils/functions/supabase';
|
import { supabase } from '$lib/utils/functions/supabase';
|
||||||
import { capturePosthogEvent } from '$lib/utils/services/posthog';
|
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 { user, profile, defaultProfileState, defaultUserState } from '$lib/utils/store/user';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
@@ -12,8 +11,6 @@ export async function logout(redirect = true) {
|
|||||||
console.error('Error logging out: ', error);
|
console.error('Error logging out: ', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentOrg.set(defaultCurrentOrgState);
|
|
||||||
orgs.set([]);
|
|
||||||
user.set(defaultUserState);
|
user.set(defaultUserState);
|
||||||
profile.set(defaultProfileState);
|
profile.set(defaultProfileState);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user