feat(auth): "beni 30 gün hatırla" + login Turnstile koruması
- session.expiresIn = 30 gün; login'de rememberMe checkbox signIn.email'e bağlandı (işaretli=30 gün kalıcı çerez, değilse oturum çerezi) - better-auth captcha plugin'i (cloudflare-turnstile, TURNSTILE_SECRET_KEY varsa) sign-in/sign-up'ı korur; login formuna Turnstile widget'ı + x-captcha-response Not: auth.ts ve login.tsx her iki özelliği birlikte içerdiğinden tek commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { generateReferralCode } from "@sase/shared";
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { captcha } from "better-auth/plugins";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
@@ -165,6 +166,9 @@ export function createAuth(
|
||||
},
|
||||
},
|
||||
session: {
|
||||
// "Beni hatırla" işaretliyse oturum 30 gün korunur; işaretli değilse
|
||||
// better-auth çerezi oturum çerezi yapar (tarayıcı kapanınca silinir).
|
||||
expiresIn: 60 * 60 * 24 * 30, // 30 gün
|
||||
cookieCache: {
|
||||
enabled: true,
|
||||
maxAge: 60 * 5, // 5 minutes
|
||||
@@ -198,6 +202,19 @@ export function createAuth(
|
||||
...(process.env.CORS_ORIGIN || "http://localhost:3000").split(","),
|
||||
"http://localhost:4000",
|
||||
],
|
||||
plugins: [
|
||||
// Cloudflare Turnstile: yalnızca secret tanımlıysa aktif. sign-in/sign-up
|
||||
// uçları "x-captcha-response" header'ındaki token ile doğrulanır.
|
||||
...(process.env.TURNSTILE_SECRET_KEY
|
||||
? [
|
||||
captcha({
|
||||
provider: "cloudflare-turnstile",
|
||||
secretKey: process.env.TURNSTILE_SECRET_KEY,
|
||||
endpoints: ["/sign-in/email", "/sign-up/email"],
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
|
||||
return authInstance;
|
||||
|
||||
Reference in New Issue
Block a user