Files
butcem/src/shared/schemas/common.ts
T
suphicakir 5191a5cce1 feat(auth): Better Auth, kullanıcı adı ile giriş, DAL ve proxy
- MongoDB/Mongoose bağlantıları, kayıt kapalı, admin + username plugin, rate limit
- DAL: getCurrentUser, requireSession, requireRole, getActionUser
- Kullanıcı adı normalizasyonu: İ/I/ı → i (tr-TR 'ADMIN' → 'admın' hatası)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 02:02:00 +03:00

43 lines
1.5 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 { z } from "zod";
import { tr } from "../../i18n/tr";
const v = tr.validation;
/** Sistem rolleri (Better Auth admin plugin). */
export const SYSTEM_ROLES = ["admin", "user"] as const;
export const systemRoleSchema = z.enum(SYSTEM_ROLES);
export type SystemRole = z.infer<typeof systemRoleSchema>;
export const USERNAME_PATTERN = /^[a-z0-9._]{3,30}$/;
export const nameSchema = z.string().trim().min(2, v.nameMin).max(80, v.nameMax);
/**
* Kullanıcı adı normalizasyonu (ASCII). Türkçe yerel ayarı KULLANILMAZ: tr-TR'de "I" → "ı" olur
* ve "ADMIN" "admın"e dönüşür. Bunun yerine İ/I/ı hepsi "i" yapılır, sonra küçük harfe çevrilir.
*/
export function normalizeUsername(value: string): string {
return value.trim().replace(/[İIı]/g, "i").toLowerCase();
}
export const usernameSchema = z
.string()
.transform(normalizeUsername)
.pipe(z.string().regex(USERNAME_PATTERN, v.usernameFormat));
export const emailSchema = z.string().trim().toLowerCase().pipe(z.email(v.email));
/** Boş bırakılabilen e-posta: "" → undefined. */
export const optionalEmailSchema = z
.string()
.trim()
.transform((s) => (s === "" ? undefined : s.toLowerCase()))
.pipe(z.email(v.email).optional());
export const passwordSchema = z.string().min(8, v.passwordMin).max(128, v.passwordMax);
/** Girilen değer e-posta mı (giriş sırasında e-posta/kullanıcı adı yöntemini seçmek için)? */
export function looksLikeEmail(value: string): boolean {
return value.includes("@");
}