refactor(auth): implement token-based authentication with JWT parsing

- Replace authStore with tokenService for authentication management
- Add JWT parsing utility to extract user info from tokens
- Update login flow to use cookie-based token storage
- Modify logout to properly clear auth state and cookies
- Integrate user data into page context for SSR compatibility
- Remove deprecated authStore and related localStorage logic
- Add cookie constants for consistent token handling
- Implement server-side token validation in hooks
- Update HTTP client to use token from cookies instead of store
- Refactor error handling to use unified ApiError class
- Replace manual redirect logic with resolved paths
- Improve type safety with explicit user and auth interfaces
- Add toast notifications for login/logout feedback
- Remove unused sidebar store and related UI logic
- Migrate theme handling to use cookies and context
- Update icon definitions and component references
- Clean up legacy code and unused imports
This commit is contained in:
Chaos
2025-11-25 16:53:48 +08:00
parent 8f3f2d63a0
commit 4ec8e88e58
32 changed files with 437 additions and 381 deletions

View File

@@ -1,16 +1,15 @@
<script lang="ts">
import { themeStore } from '$lib/stores/themeStore.ts';
import { DAISYUI_THEME_OPTIONS, type DaisyUIThemeID } from '$lib/types/theme.ts';
import { DAISYUI_THEME_OPTIONS } from '$lib/types/theme.ts';
import ThemePreview from '$lib/widget/ThemePreview.svelte';
import { getContext } from 'svelte';
import { THEME_KEY, ThemeState } from '$lib/stores/theme.svelte.ts';
const themeState = getContext<ThemeState>(THEME_KEY);
const handleThemeChange = (themeValue: DaisyUIThemeID) => {
themeStore.set(themeValue);
};
</script>
<div class="dropdown dropdown-center md:dropdown-end ">
<div tabindex="0" role="button" class="rounded hover:bg-base-100 active:bg-base-200 p-2 overflow-hidden flex items-center gap-2">
<ThemePreview themeId={$themeStore} />
<ThemePreview themeId={themeState.theme} />
<svg width="12px" height="12px" class="mt-px text-base-content size-2 fill-current opacity-60 sm:inline-block" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2048 2048"><path d="M1799 349l242 241-1017 1017L7 590l242-241 775 775 775-775z"></path></svg>
</div>
@@ -24,14 +23,14 @@
<div
role="button"
tabindex="0"
on:click={() => handleThemeChange(theme.value)}
on:keydown={(e) => {
onclick={() => themeState.setTheme(theme.value)}
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handleThemeChange(theme.value);
themeState.setTheme(theme.value);
}
}}
class="gap-3 w-full flex hover:bg-base-300 active:bg-primary p-2 items-center {theme.value === $themeStore ? 'active' : ''}"
class="gap-3 w-full flex hover:bg-base-300 active:bg-primary p-2 items-center {theme.value === themeState.theme ? 'active' : ''}"
>
<ThemePreview themeId={theme.value} />
<div class=" ">{theme.name}</div>