Various improvements

This commit is contained in:
Stefan Hardegger
2025-08-21 13:55:38 +02:00
parent 35a5825e76
commit a660056003
11 changed files with 829 additions and 55 deletions

View File

@@ -2,7 +2,7 @@
import { createContext, useContext, useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { authApi, setGlobalAuthFailureHandler } from '../lib/api';
import { authApi, setGlobalAuthFailureHandler, setCurrentLibraryId } from '../lib/api';
import { preloadSanitizationConfig } from '../lib/sanitization';
interface AuthContextType {
@@ -34,6 +34,19 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
try {
const authenticated = authApi.isAuthenticated();
setIsAuthenticated(authenticated);
// If authenticated, also load current library for image URLs
if (authenticated) {
try {
const response = await fetch('/api/libraries/current');
if (response.ok) {
const library = await response.json();
setCurrentLibraryId(library.id);
}
} catch (error) {
console.error('Failed to load current library:', error);
}
}
} catch (error) {
console.error('Auth check failed:', error);
setIsAuthenticated(false);
@@ -59,6 +72,17 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
try {
await authApi.login(password);
setIsAuthenticated(true);
// Load current library after successful login
try {
const response = await fetch('/api/libraries/current');
if (response.ok) {
const library = await response.json();
setCurrentLibraryId(library.id);
}
} catch (error) {
console.error('Failed to load current library after login:', error);
}
} catch (error) {
console.error('Login failed:', error);
throw error;