fix: Node 26 uyumsuzluğunu çöz — node-appwrite -> appwrite SDK
Sorun:
- node-appwrite paketi 'node-fetch-native-with-agent' polyfill'i kullanıyor
- Node.js 26'nın undici implementation'ı ile uyumsuz
- 'fetch failed / InvalidArgumentError: invalid onError method' hatası
- Login dahil tüm Appwrite çağrıları başarısız
Çözüm:
- Tüm node-appwrite kullanımını browser SDK 'appwrite'a geçir
- Browser SDK native fetch kullanıyor, Node 26 uyumlu
- API key tabanlı admin client yerine session cookie tabanlı user client
- Public reads (read('any')): publicDB (auth'suz client)
- Admin CRUD: userDB(sessionSecret) (cookie'deki session)
- Storage upload doğrudan File objesi alıyor (InputFile.fromBuffer gerekmez)
Etkilenen dosyalar:
- lib/appwrite-server.ts: publicClient + sessionClient
- lib/auth.ts: requireSessionSecret eklendi
- lib/admin-actions.ts: tüm action'lar sessionClient kullanıyor
- app/actions.ts: publicDB
- lib/data.ts: publicDB
- app/admin/login/actions.ts: appwrite SDK
- app/admin/(protected)/page.tsx, medya/page.tsx: userDB/userStorage
End-to-end test edildi:
✓ Login (401 doğru hata)
✓ Public read (services)
✓ Anonim create (contact form)
✓ npm run build 23 route
This commit is contained in:
+11
-10
@@ -1,6 +1,6 @@
|
||||
import "server-only";
|
||||
import { Query } from "node-appwrite";
|
||||
import { adminDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
|
||||
import { Query } from "appwrite";
|
||||
import { publicDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
|
||||
import type {
|
||||
BlogPostRow,
|
||||
ContactMessageRow,
|
||||
@@ -11,12 +11,9 @@ import type {
|
||||
TestimonialRow,
|
||||
} from "@/lib/types";
|
||||
|
||||
async function safeList<T>(
|
||||
tableId: string,
|
||||
queries: string[],
|
||||
): Promise<T[]> {
|
||||
async function safeList<T>(tableId: string, queries: string[]): Promise<T[]> {
|
||||
try {
|
||||
const res = await adminDB.listRows<T extends import("appwrite").Models.Row ? T : never>({
|
||||
const res = await publicDB.listRows({
|
||||
databaseId: DATABASE_ID,
|
||||
tableId,
|
||||
queries,
|
||||
@@ -91,11 +88,11 @@ export async function listSeoPages() {
|
||||
|
||||
export async function getSeoSettings(): Promise<SeoSettingsRow | null> {
|
||||
try {
|
||||
return await adminDB.getRow<SeoSettingsRow>({
|
||||
return (await publicDB.getRow({
|
||||
databaseId: DATABASE_ID,
|
||||
tableId: TABLES.seoSettings,
|
||||
rowId: "global",
|
||||
});
|
||||
})) as unknown as SeoSettingsRow;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -103,7 +100,11 @@ export async function getSeoSettings(): Promise<SeoSettingsRow | null> {
|
||||
|
||||
export async function getRow<T>(tableId: string, rowId: string): Promise<T | null> {
|
||||
try {
|
||||
return (await adminDB.getRow({ databaseId: DATABASE_ID, tableId, rowId })) as T;
|
||||
return (await publicDB.getRow({
|
||||
databaseId: DATABASE_ID,
|
||||
tableId,
|
||||
rowId,
|
||||
})) as unknown as T;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user