feat: kimlik doğrulama, ödeme, kredi ve AI rapor sihirbazı ekle
- better-auth ile giriş/oturum yönetimi (src/lib/auth, giris sayfası) - iyzico ödeme entegrasyonu ve paket satın alma akışı - kredi sistemi ve uygulama veritabanı şeması (drizzle) - AI destekli rapor üretimi ve tercih sihirbazı - rapor yazdırma sayfası ve site header/kullanıcı menüsü Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
35
src/lib/session.ts
Normal file
35
src/lib/session.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
});
|
||||
Reference in New Issue
Block a user