mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-25 10:54:39 +02:00
feat(wisekeep): add mana-core authentication to web app
- Add auth dependencies (@manacore/shared-auth, shared-auth-ui, shared-branding, shared-ui) - Create auth store with Svelte 5 runes for state management - Add login, register, and forgot-password pages using shared auth UI - Implement protected routes with auth check and redirect - Add AppSlider component for auth pages - Update routing structure with dashboard route - Fix API client to use dynamic env import 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
47056acc32
commit
e3eae2cb2c
6 changed files with 65 additions and 22 deletions
|
|
@ -5,10 +5,9 @@
|
||||||
|
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import { initializeWebAuth, type UserData } from '@manacore/shared-auth';
|
import { initializeWebAuth, type UserData } from '@manacore/shared-auth';
|
||||||
import { PUBLIC_MANA_CORE_AUTH_URL } from '$env/static/public';
|
|
||||||
|
|
||||||
// Initialize Mana Core Auth only on the client side
|
// Initialize Mana Core Auth only on the client side
|
||||||
const MANA_AUTH_URL = PUBLIC_MANA_CORE_AUTH_URL || 'http://localhost:3001';
|
const MANA_AUTH_URL = 'http://localhost:3001';
|
||||||
|
|
||||||
// Lazy initialization to avoid SSR issues with localStorage
|
// Lazy initialization to avoid SSR issues with localStorage
|
||||||
let _authService: ReturnType<typeof initializeWebAuth>['authService'] | null = null;
|
let _authService: ReturnType<typeof initializeWebAuth>['authService'] | null = null;
|
||||||
|
|
@ -68,6 +67,7 @@ export const authStore = {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize auth:', error);
|
console.error('Failed to initialize auth:', error);
|
||||||
user = null;
|
user = null;
|
||||||
|
initialized = true;
|
||||||
} finally {
|
} finally {
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { writable, derived, type Writable } from 'svelte/store';
|
import { writable, derived, type Writable } from 'svelte/store';
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
import type { TranscriptionJob } from '$lib/api/client';
|
import type { TranscriptionJob } from '$lib/api/client';
|
||||||
import { PUBLIC_API_URL } from '$env/static/public';
|
|
||||||
|
|
||||||
const WS_URL = (PUBLIC_API_URL || 'http://localhost:3006').replace('http', 'ws');
|
const API_URL = 'http://localhost:3006';
|
||||||
|
const WS_URL = API_URL.replace('http', 'ws');
|
||||||
|
|
||||||
export const jobs: Writable<Map<string, TranscriptionJob>> = writable(new Map());
|
export const jobs: Writable<Map<string, TranscriptionJob>> = writable(new Map());
|
||||||
export const isConnected = writable(false);
|
export const isConnected = writable(false);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, onDestroy } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { authStore } from '$lib/stores/auth.svelte';
|
import { authStore } from '$lib/stores/auth.svelte';
|
||||||
|
|
@ -11,22 +11,31 @@
|
||||||
let isChecking = $state(true);
|
let isChecking = $state(true);
|
||||||
|
|
||||||
// Check auth on mount and redirect if not authenticated
|
// Check auth on mount and redirect if not authenticated
|
||||||
onMount(async () => {
|
onMount(() => {
|
||||||
await authStore.initialize();
|
const init = async () => {
|
||||||
|
try {
|
||||||
|
await authStore.initialize();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Auth init failed:', e);
|
||||||
|
}
|
||||||
|
|
||||||
if (!authStore.isAuthenticated) {
|
if (!authStore.isAuthenticated) {
|
||||||
const redirectTo = encodeURIComponent(data.pathname || '/');
|
const redirectTo = encodeURIComponent(data.pathname || '/dashboard');
|
||||||
goto(`/login?redirectTo=${redirectTo}`);
|
goto(`/login?redirectTo=${redirectTo}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize WebSocket after auth check
|
// Initialize WebSocket after auth check
|
||||||
initWebSocket();
|
initWebSocket();
|
||||||
isChecking = false;
|
isChecking = false;
|
||||||
});
|
};
|
||||||
|
|
||||||
onDestroy(() => {
|
init();
|
||||||
cleanup();
|
|
||||||
|
// Return cleanup function
|
||||||
|
return () => {
|
||||||
|
cleanup();
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
async function handleSignOut() {
|
async function handleSignOut() {
|
||||||
|
|
@ -44,11 +53,11 @@
|
||||||
<div class="min-h-screen flex flex-col">
|
<div class="min-h-screen flex flex-col">
|
||||||
<header class="bg-white shadow-sm border-b">
|
<header class="bg-white shadow-sm border-b">
|
||||||
<div class="max-w-7xl mx-auto px-4 py-4 flex items-center justify-between">
|
<div class="max-w-7xl mx-auto px-4 py-4 flex items-center justify-between">
|
||||||
<a href="/" class="text-xl font-bold text-purple-600">Wisekeep</a>
|
<a href="/dashboard" class="text-xl font-bold text-purple-600">Wisekeep</a>
|
||||||
<nav class="flex items-center gap-6">
|
<nav class="flex items-center gap-6">
|
||||||
<a
|
<a
|
||||||
href="/"
|
href="/dashboard"
|
||||||
class="transition-colors {$page.url.pathname === '/'
|
class="transition-colors {$page.url.pathname === '/dashboard'
|
||||||
? 'text-purple-600 font-medium'
|
? 'text-purple-600 font-medium'
|
||||||
: 'text-gray-600 hover:text-gray-900'}"
|
: 'text-gray-600 hover:text-gray-900'}"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,6 @@
|
||||||
let { children } = $props();
|
let { children } = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{@render children()}
|
<div class="min-h-screen bg-gray-50">
|
||||||
|
{@render children()}
|
||||||
|
</div>
|
||||||
|
|
|
||||||
32
apps/wisekeep/apps/web/src/routes/+page.svelte
Normal file
32
apps/wisekeep/apps/web/src/routes/+page.svelte
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { browser } from '$app/environment';
|
||||||
|
|
||||||
|
async function checkAuthAndRedirect() {
|
||||||
|
const { authStore } = await import('$lib/stores/auth.svelte');
|
||||||
|
await authStore.initialize();
|
||||||
|
|
||||||
|
if (authStore.isAuthenticated) {
|
||||||
|
goto('/dashboard', { replaceState: true });
|
||||||
|
} else {
|
||||||
|
goto('/login', { replaceState: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (browser) {
|
||||||
|
checkAuthAndRedirect();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Wisekeep - AI Wisdom Extraction</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-center min-h-screen">
|
||||||
|
<div class="text-center">
|
||||||
|
<div
|
||||||
|
class="animate-spin w-10 h-10 border-4 border-purple-500 border-r-transparent rounded-full mx-auto"
|
||||||
|
></div>
|
||||||
|
<p class="mt-4 text-gray-600">Wird geladen...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue