fix: sync reorder transaction + redirect unauthenticated users to wishlist
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Docker Image / build-and-push (push) Has been cancelled
- reorder route used async callback with better-sqlite3 (sync driver), causing "Transaction function cannot return a promise" — converted to sync - home page now redirects unauthenticated visitors to the wishlist slug instead of getting stuck on the loading screen Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,24 +90,25 @@ export async function POST(
|
|||||||
allItems.splice(newSortOrder, 0, movingItem);
|
allItems.splice(newSortOrder, 0, movingItem);
|
||||||
|
|
||||||
// Update all sortOrders in a transaction for atomicity
|
// Update all sortOrders in a transaction for atomicity
|
||||||
const updatedItem = await db.transaction(async (tx) => {
|
// Note: better-sqlite3 is synchronous, so no async/await in transaction
|
||||||
// Update all sortOrders
|
const updatedItem = db.transaction((tx) => {
|
||||||
for (let i = 0; i < allItems.length; i++) {
|
for (let i = 0; i < allItems.length; i++) {
|
||||||
await tx
|
tx.update(wishlistItems)
|
||||||
.update(wishlistItems)
|
|
||||||
.set({
|
.set({
|
||||||
sortOrder: i,
|
sortOrder: i,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(wishlistItems.id, allItems[i].id));
|
.where(eq(wishlistItems.id, allItems[i].id))
|
||||||
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the updated moving item
|
// Get the updated moving item
|
||||||
const result = await tx
|
const result = tx
|
||||||
.select()
|
.select()
|
||||||
.from(wishlistItems)
|
.from(wishlistItems)
|
||||||
.where(eq(wishlistItems.id, id))
|
.where(eq(wishlistItems.id, id))
|
||||||
.limit(1);
|
.limit(1)
|
||||||
|
.all();
|
||||||
|
|
||||||
return result[0];
|
return result[0];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,7 +37,11 @@ export default function HomePage() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Unauthenticated — show a simple landing
|
// Unauthenticated — redirect to wishlist anyway (GuestGuard will block them there)
|
||||||
|
const lists = await wishlistsApi.getAllPublic();
|
||||||
|
if (!cancelled && lists.length > 0) {
|
||||||
|
router.replace(`/${lists[0].slug}`);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user