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:
+20
-14
@@ -1,9 +1,8 @@
|
||||
import "server-only";
|
||||
import { Account, Client, Storage, TablesDB } from "node-appwrite";
|
||||
import { Account, Client, Storage, TablesDB } from "appwrite";
|
||||
|
||||
const endpoint = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT!;
|
||||
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID!;
|
||||
const apiKey = process.env.APPWRITE_API_KEY;
|
||||
|
||||
export const DATABASE_ID = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID!;
|
||||
export const MEDIA_BUCKET_ID =
|
||||
@@ -19,21 +18,28 @@ export const TABLES = {
|
||||
seoSettings: "seo_settings",
|
||||
} as const;
|
||||
|
||||
export function adminClient() {
|
||||
const c = new Client().setEndpoint(endpoint).setProject(projectId);
|
||||
if (apiKey) c.setKey(apiKey);
|
||||
return c;
|
||||
function newClient() {
|
||||
return new Client().setEndpoint(endpoint).setProject(projectId);
|
||||
}
|
||||
|
||||
export function publicClient() {
|
||||
return newClient();
|
||||
}
|
||||
|
||||
export function sessionClient(sessionSecret: string) {
|
||||
return new Client()
|
||||
.setEndpoint(endpoint)
|
||||
.setProject(projectId)
|
||||
.setSession(sessionSecret);
|
||||
return newClient().setSession(sessionSecret);
|
||||
}
|
||||
|
||||
export const adminDB = new TablesDB(adminClient());
|
||||
export const adminStorage = new Storage(adminClient());
|
||||
export const adminAccount = new Account(adminClient());
|
||||
export const publicDB = new TablesDB(publicClient());
|
||||
export const publicStorage = new Storage(publicClient());
|
||||
export const publicAccount = new Account(publicClient());
|
||||
|
||||
export { Account, TablesDB, Storage };
|
||||
export function userDB(secret: string) {
|
||||
return new TablesDB(sessionClient(secret));
|
||||
}
|
||||
export function userStorage(secret: string) {
|
||||
return new Storage(sessionClient(secret));
|
||||
}
|
||||
export function userAccount(secret: string) {
|
||||
return new Account(sessionClient(secret));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user