auth: login pill toggle for clinic/lab + server-side kind validation

Sign-in form now has a Klinik / Laboratuvar pill toggle (defaults to clinic).
The selected kind is posted alongside email+password; the server action
resolves the user's memberships, picks a tenant_settings row matching the
chosen kind, and sets it as active. If no matching tenant exists the session
is rolled back with a clear error.

Invite-flow logins skip the kind check — invite code drives team assignment.
This commit is contained in:
kovakmedya
2026-05-21 18:39:45 +03:00
parent cb150f7a24
commit 92c3b53e39
2 changed files with 149 additions and 6 deletions
@@ -1,8 +1,8 @@
"use client";
import Link from "next/link";
import { useActionState } from "react";
import { Loader2 } from "lucide-react";
import { useActionState, useState } from "react";
import { FlaskConical, Loader2, Stethoscope } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
@@ -13,11 +13,14 @@ import { cn } from "@/lib/utils";
import { signInAction } from "@/lib/appwrite/auth-actions";
import { initialAuthState } from "@/lib/appwrite/auth-types";
type Kind = "clinic" | "lab";
export function LoginForm1({
className,
inviteCode,
...props
}: React.ComponentProps<"div"> & { inviteCode?: string }) {
const [kind, setKind] = useState<Kind>("clinic");
const [state, formAction, isPending] = useActionState(signInAction, initialAuthState);
return (
@@ -26,6 +29,7 @@ export function LoginForm1({
<CardContent className="grid p-0 md:grid-cols-2">
<form action={formAction} className="p-6 md:p-10">
{inviteCode && <input type="hidden" name="inviteCode" value={inviteCode} />}
<input type="hidden" name="kind" value={kind} />
<div className="flex flex-col gap-6">
<div className="flex justify-center">
<Link href="/" className="flex items-center gap-2 font-medium">
@@ -45,10 +49,14 @@ export function LoginForm1({
<div className="flex flex-col items-center text-center">
<h1 className="text-2xl font-bold tracking-tight">Tekrar hoş geldiniz</h1>
<p className="text-muted-foreground text-sm text-balance mt-1">
Hesabınıza giriş yaparak işletmenizi yönetmeye devam edin
Hesabınıza giriş yapın
</p>
</div>
{!inviteCode && (
<KindPill value={kind} onChange={setKind} disabled={isPending} />
)}
<div className="grid gap-3">
<Label htmlFor="email">Email</Label>
<Input
@@ -128,6 +136,72 @@ export function LoginForm1({
);
}
function KindPill({
value,
onChange,
disabled,
}: {
value: Kind;
onChange: (next: Kind) => void;
disabled?: boolean;
}) {
return (
<div
role="radiogroup"
aria-label="Hesap türü"
className="bg-muted text-muted-foreground inline-flex w-full items-center gap-1 rounded-full border p-1"
>
<PillButton
active={value === "clinic"}
onClick={() => onChange("clinic")}
disabled={disabled}
>
<Stethoscope className="size-4" />
Klinik
</PillButton>
<PillButton
active={value === "lab"}
onClick={() => onChange("lab")}
disabled={disabled}
>
<FlaskConical className="size-4" />
Laboratuvar
</PillButton>
</div>
);
}
function PillButton({
active,
onClick,
disabled,
children,
}: {
active: boolean;
onClick: () => void;
disabled?: boolean;
children: React.ReactNode;
}) {
return (
<button
type="button"
role="radio"
aria-checked={active}
onClick={onClick}
disabled={disabled}
className={cn(
"flex flex-1 items-center justify-center gap-1.5 rounded-full px-3 py-1.5 text-sm font-medium transition-colors",
active
? "bg-background text-foreground shadow-sm"
: "hover:text-foreground",
disabled && "cursor-not-allowed opacity-60",
)}
>
{children}
</button>
);
}
function BrandPanel() {
return (
<div className="bg-primary text-primary-foreground relative hidden md:flex md:flex-col md:justify-between overflow-hidden p-10">
@@ -157,10 +231,10 @@ function BrandPanel() {
<div className="relative z-10 flex flex-col gap-3">
<h2 className="text-3xl font-semibold leading-tight">
Müşteriden faturaya, tek panelden işletmenizi yönetin.
Klinik ve laboratuvar tek panelde.
</h2>
<p className="text-primary-foreground/80 text-sm">
Müşteriler, hizmetler, takvim, görevler ve finans hepsi tek yerde, multi-tenant ve ekibinize özel.
İş yayınla, taranan dosyaları paylaş, protez aşamalarını adım adım takip et finansal akışla birlikte.
</p>
<div className="text-primary-foreground/70 mt-4 text-xs">Kovak Yazılım tarafından</div>
</div>