4dbd2eb441
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
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ı küçük harfe çevrilir; Türkçe büyük İ/I sorununu önlemek için tr-TR kullanılır. */
|
||
export const usernameSchema = z
|
||
.string()
|
||
.trim()
|
||
.transform((s) => s.toLocaleLowerCase("tr-TR"))
|
||
.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("@");
|
||
}
|