Skip to content

Commit

Permalink
Improve login behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Apr 13, 2024
1 parent 730eae2 commit ef94e34
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/lib/stores/UserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { usersApi } from "$lib/api";
import type { ApiUser, ApiUserSelf } from "$lib/types/ApiUser";
import { writable } from "svelte/store";


export const UserSelfStore = writable<ApiUserSelf | null>(null);
export const UsersStore = writable<ApiUser[]>([]);

if (browser) {
export function refreshUserSelf() {
if (!browser) return;

usersApi.usersGetSelf().then(({ data, message }) => {
if (!data) {
console.error(`Failed to get user self: ${message}`);
Expand All @@ -28,3 +29,5 @@ if (browser) {
console.error(error);
});
}

refreshUserSelf();
5 changes: 4 additions & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { modalRegistry } from '$lib/modals';
import { page } from '$app/stores';
import { buildMetaData } from '$lib/metadata';
import { UserSelfStore } from '$lib/stores/UserStore';
storePopup.set({ computePosition, autoUpdate, flip, shift, offset, arrow });
initializeStores();
Expand All @@ -25,7 +26,9 @@

<AppShell>
<Header slot="header" />
<Sidebar slot="sidebarLeft" />
{#if $UserSelfStore}
<Sidebar slot="sidebarLeft" />
{/if}
<slot />
<Footer slot="pageFooter" />
</AppShell>
2 changes: 2 additions & 0 deletions src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { accountApi } from '$lib/api';
import PasswordInput from '$lib/components/PasswordInput.svelte';
import TextInput from '$lib/components/TextInput.svelte';
import { refreshUserSelf } from '$lib/stores/UserStore';
import type { ValidationResult } from '$lib/types/ValidationResult';
let usernameOrEmail = '';
Expand All @@ -15,6 +16,7 @@
accountApi
.accountLogin({ email: usernameOrEmail, password })
.then(() => {
refreshUserSelf();
goto('/home');
})
.catch((err) => {
Expand Down

0 comments on commit ef94e34

Please sign in to comment.