fix(auth): SDK'yı kaldırıp ince REST katmanına geç (lib/appwrite-rest.ts)
Sorun: - node-appwrite v20-25 hepsi Node 26'da bozuk (node-fetch-native-with-agent polyfill) - appwrite browser SDK Server Action context'inde 'unexpected response' veriyor (büyük olasılıkla browser-only global'ları kontrol ederken) Çözüm: - Tüm Appwrite SDK'larını sil (appwrite + node-appwrite) - lib/appwrite-rest.ts: native fetch üzerinde ~250 satırlık ince REST wrapper - account: createEmailPasswordSession, get, deleteSession - tablesDB: listRows, getRow, createRow, updateRow, deleteRow - storage: listFiles, createFile, deleteFile, fileViewUrl - Q helpers: equal, orderAsc/Desc, limit, offset - AppwriteError class - Session secret cookie tabanlı auth korundu (isletmem-kovakcrm'deki desen) - Tüm CRUD action ve query'ler REST katmanına bağlandı End-to-end test edildi: ✓ Login (proper 401 hata mesajları, başarılı durumda redirect) ✓ Public read (services, blog, testimonials) ✓ Anonim create (contact form) ✓ Build (24 route) ✓ Sıfır SDK bağımlılığı — Node 26 sorunu yok
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import Link from "next/link";
|
||||
import { ArrowRight } from "lucide-react";
|
||||
import { Query } from "appwrite";
|
||||
import { DATABASE_ID, TABLES, userDB } from "@/lib/appwrite-server";
|
||||
import { DATABASE_ID, Q, TABLES, tablesDB } from "@/lib/appwrite-rest";
|
||||
import { requireSessionSecret } from "@/lib/auth";
|
||||
|
||||
async function safeCount(tableId: string, queries: string[] = []) {
|
||||
try {
|
||||
const secret = await requireSessionSecret();
|
||||
const res = await userDB(secret).listRows({
|
||||
databaseId: DATABASE_ID,
|
||||
const res = await tablesDB.listRows(
|
||||
DATABASE_ID,
|
||||
tableId,
|
||||
queries: [...queries, Query.limit(1)],
|
||||
});
|
||||
[...queries, Q.limit(1)],
|
||||
secret,
|
||||
);
|
||||
return res.total ?? 0;
|
||||
} catch {
|
||||
return 0;
|
||||
@@ -21,12 +21,12 @@ async function safeCount(tableId: string, queries: string[] = []) {
|
||||
export default async function AdminDashboard() {
|
||||
const [posts, drafts, services, projects, testimonials, newMessages, totalMessages] =
|
||||
await Promise.all([
|
||||
safeCount(TABLES.blogPosts, [Query.equal("status", "published")]),
|
||||
safeCount(TABLES.blogPosts, [Query.equal("status", "draft")]),
|
||||
safeCount(TABLES.blogPosts, [Q.equal("status", "published")]),
|
||||
safeCount(TABLES.blogPosts, [Q.equal("status", "draft")]),
|
||||
safeCount(TABLES.services),
|
||||
safeCount(TABLES.projects),
|
||||
safeCount(TABLES.testimonials),
|
||||
safeCount(TABLES.contactMessages, [Query.equal("status", "new")]),
|
||||
safeCount(TABLES.contactMessages, [Q.equal("status", "new")]),
|
||||
safeCount(TABLES.contactMessages),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user