This commit is contained in:
alma 2025-05-04 15:57:26 +02:00
parent 1fa83110a3
commit a3bc5871c3
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,33 @@
import { NextResponse } from 'next/server';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import { createUserFolderStructure } from '@/lib/s3';
export async function GET(request: Request) {
try {
// Get session
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const userId = session.user.id;
console.log(`Manually creating all folders for user: ${userId}`);
// Create the folder structure for the user
const result = await createUserFolderStructure(userId);
return NextResponse.json({
success: true,
message: 'All folders created successfully',
userId
});
} catch (error) {
console.error('Error creating folders:', error);
return NextResponse.json({
error: 'Failed to create folders',
message: error instanceof Error ? error.message : String(error)
}, { status: 500 });
}
}

View File

@ -130,10 +130,27 @@ export default function CarnetPage() {
if (status === "unauthenticated") {
redirect("/signin");
}
if (status === "authenticated" && session?.user?.id) {
// Initialize all folders when user logs in
fetch('/api/storage/init', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}).then(response => {
if (response.ok) {
console.log('All folders initialized successfully');
} else {
console.error('Failed to initialize folders');
}
}).catch(error => {
console.error('Error initializing folders:', error);
});
}
if (status !== "loading") {
setIsLoading(false);
}
}, [status]);
}, [status, session?.user?.id]);
useEffect(() => {
if (isSmallScreen) {