Various improvements
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user