4096b3d87b
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
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
"use server";
|
||
|
||
import { ID } from "appwrite";
|
||
import { publicDB, DATABASE_ID, TABLES } from "@/lib/appwrite-server";
|
||
|
||
export type ContactFormState = {
|
||
ok: boolean;
|
||
message: string;
|
||
errors?: Record<string, string>;
|
||
};
|
||
|
||
const initial: ContactFormState = { ok: false, message: "" };
|
||
|
||
export async function submitContact(
|
||
_prev: ContactFormState = initial,
|
||
formData: FormData,
|
||
): Promise<ContactFormState> {
|
||
const name = String(formData.get("name") ?? "").trim();
|
||
const email = String(formData.get("email") ?? "").trim();
|
||
const phone = String(formData.get("phone") ?? "").trim();
|
||
const subject = String(formData.get("subject") ?? "").trim();
|
||
const message = String(formData.get("message") ?? "").trim();
|
||
|
||
const errors: Record<string, string> = {};
|
||
if (!name) errors.name = "Ad zorunlu";
|
||
if (!email) errors.email = "E-posta zorunlu";
|
||
else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email))
|
||
errors.email = "Geçerli bir e-posta girin";
|
||
if (!message || message.length < 10)
|
||
errors.message = "Mesaj en az 10 karakter olmalı";
|
||
|
||
if (Object.keys(errors).length > 0) {
|
||
return { ok: false, message: "Lütfen form alanlarını kontrol edin", errors };
|
||
}
|
||
|
||
try {
|
||
await publicDB.createRow({
|
||
databaseId: DATABASE_ID,
|
||
tableId: TABLES.contactMessages,
|
||
rowId: ID.unique(),
|
||
data: {
|
||
name,
|
||
email,
|
||
phone: phone || null,
|
||
subject: subject || null,
|
||
message,
|
||
status: "new",
|
||
},
|
||
});
|
||
return { ok: true, message: "Mesajınız iletildi. En kısa sürede dönüş yapacağız." };
|
||
} catch (err) {
|
||
const detail = err instanceof Error ? err.message : "Bilinmeyen hata";
|
||
return { ok: false, message: `Kayıt başarısız: ${detail}` };
|
||
}
|
||
}
|