Files
kolaytercih/src/lib/session.ts
bilalgursen 820eea7eca refactor: ortak tipler @/types/yokatlas + features/rapor/types'a çıkarıldı, server-only korumaları eklendi (Faz 1)
- Program/PUAN_TURLERI/DilimKey/RankResults/UniturGrubu/ProgramNetSatiri/
  SihirbazFacetleri artık src/types/yokatlas.ts'te; lib/db.ts yalnızca sorgu
  fonksiyonları barındırıyor
- RaporSonuc/RaporKapsam/RaporParams/MaskeliRapor src/features/rapor/types/
  rapor.ts'e taşındı; ölü kalan TercihSchema/RaporSchema silindi
- 11 lib dosyasına import "server-only" eklendi; scripts'in düz node ile
  import ettiği dosyalara (db, appdb, rapor-havuzu, tadimlik-havuzu, ai/client,
  ai/cagri, credits) bilinçli eklenmedi
- Davranış değişikliği yok; pnpm build yeşil

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 01:06:06 +03:00

36 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import "server-only";
import { cache } from "react";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { eq } from "drizzle-orm";
import { auth } from "./auth";
import { appDb, schema } from "./appdb";
/** İstek başına tek session sorgusu (React cache). */
export const getSession = cache(async () => {
return auth.api.getSession({ headers: await headers() });
});
/** Oturum yoksa /giris'e yönlendirir; callback ile geri dönüş desteklenir. */
export async function verifySession(callbackPath?: string) {
const session = await getSession();
if (!session) {
const target = callbackPath
? `/giris?callback=${encodeURIComponent(callbackPath)}`
: "/giris";
redirect(target);
}
return session;
}
/** Kredi/paket alanları dahil güncel kullanıcı satırı (session cache'ine güvenme). */
export const getCurrentUser = cache(async () => {
const session = await getSession();
if (!session) return null;
const rows = await appDb
.select()
.from(schema.user)
.where(eq(schema.user.id, session.user.id))
.limit(1);
return rows[0] ?? null;
});