Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
chore: use user-store for storing user
Kyle Mendellc124cddf3468
diff --git a/frontend/src/lib/services/api/auth-api-service.ts b/frontend/src/lib/services/api/auth-api-service.tsindex 86e172795..eaaa62a9c 100644--- a/frontend/src/lib/services/api/auth-api-service.ts+++ b/frontend/src/lib/services/api/auth-api-service.ts@@ -2,6 +2,7 @@ import { goto } from '$app/navigation';import { browser } from '$app/environment';import { invalidateAll } from '$app/navigation';import BaseAPIService from './api-service';+import userStore from '$lib/stores/user-store';export interface LoginCredentials {username: string;@@ -19,13 +20,18 @@ export class AuthService extends BaseAPIService {async login(credentials: LoginCredentials): Promise<User> {try {const response = await this.api.post('/auth/login', credentials);+ const user = response.data.user || response.data.data;++ // Store user in the store+ if (user) {+ userStore.setUser(user);+ }- // Invalidate all data to trigger refetch of layout dataif (browser) {await invalidateAll();}- return response.data.data;+ return user;} catch (error: any) {const errorMessage = error.response?.data?.error || 'Login failed';throw new Error(errorMessage);@@ -38,7 +44,9 @@ export class AuthService extends BaseAPIService {} catch (error) {console.error('Logout error:', error);} finally {- // Invalidate all data and redirect to login+ // Clear user from store+ userStore.clearUser();+if (browser) {await invalidateAll();goto('/auth/login');@@ -49,12 +57,17 @@ export class AuthService extends BaseAPIService {async getCurrentUser(): Promise<User | null> {try {const response = await this.api.get('/auth/me');- return response.data.data;- } catch (error: any) {- if (error.response?.status === 401) {- return null; // Not authenticated+ const user = response.data.data;++ // Store user in the store+ if (user) {+ userStore.setUser(user);}- console.error('Get current user error:', error);++ return user;+ } catch (error) {+ // Clear user from store on error+ userStore.clearUser();return null;}}@@ -62,23 +75,19 @@ export class AuthService extends BaseAPIService {async validateSession(): Promise<boolean> {try {const response = await this.api.get('/auth/validate');- return response.status === 200;+ return response.data.valid === true;} catch (error) {- console.error('Session validation error:', error);+ userStore.clearUser();return false;}}async changePassword(oldPassword: string, newPassword: string): Promise<void> {- try {- await this.api.post('/auth/change-password', {- oldPassword,- newPassword- });- } catch (error: any) {- const errorMessage = error.response?.data?.error || 'Password change failed';- throw new Error(errorMessage);- }+ const response = await this.api.post('/auth/password', {+ currentPassword: oldPassword,+ newPassword+ });+ return response.data;}}diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelteindex 8e15d5864..16b427fc0 100644--- a/frontend/src/routes/+layout.svelte+++ b/frontend/src/routes/+layout.svelte@@ -9,6 +9,7 @@import { onMount } from 'svelte';import { goto } from '$app/navigation';import { initializeClientStores } from '$lib/stores/client-init';+ import userStore from '$lib/stores/user-store';let { children, data } = $props();@@ -17,7 +18,6 @@const agents = $derived(data.agents);const isNavigating = $derived(navigating.type !== null);const isAuthenticated = $derived(!!user);-const isOnboardingPage = $derived(page.url.pathname.startsWith('/onboarding'));const isLoginPage = $derived(page.url.pathname === '/login' || page.url.pathname.startsWith('/auth/login') || page.url.pathname === '/auth' || page.url.pathname.includes('/login'));const showSidebar = $derived(isAuthenticated && !isOnboardingPage && !isLoginPage);@@ -44,12 +44,17 @@}});- onMount(() => {- const init = async () => {- await initializeClientStores();- };+ // Update user store when user data changes+ $effect(() => {+ if (user) {+ userStore.setUser(user);+ } else {+ userStore.clearUser();+ }+ });- init();+ onMount(async () => {+ await initializeClientStores();});</script>diff --git a/frontend/src/routes/auth/oidc/callback/+page.svelte b/frontend/src/routes/auth/oidc/callback/+page.svelteindex 1c933f2d1..40127929c 100644--- a/frontend/src/routes/auth/oidc/callback/+page.svelte+++ b/frontend/src/routes/auth/oidc/callback/+page.svelte@@ -4,6 +4,7 @@import { page } from '$app/state';import { oidcAPI } from '$lib/services/api';import { toast } from 'svelte-sonner';+ import userStore from '$lib/stores/user-store';let isProcessing = $state(true);let error = $state('');@@ -34,11 +35,18 @@}if (authResult.user) {- localStorage.setItem('user_data', JSON.stringify(authResult.user));+ const user = {+ id: authResult.user.sub || authResult.user.email,+ username: authResult.user.preferred_username || authResult.user.email,+ email: authResult.user.email,+ roles: (authResult.user as any).roles || [],+ createdAt: new Date().toISOString()+ };+ localStorage.setItem('user_data', JSON.stringify(user));+ userStore.setUser(user);}await invalidateAll();-toast.success('Successfully logged in!');goto(finalRedirectTo);} catch (err: any) {