feat: replace login route with auth modal

- Add AuthModal to root layout driven by ?modal=auth search param
- Update multiplayer and play beforeLoad redirects to use modal
- Update NavAuth and Hero links to use modal
- Delete login route and NavLogin component
This commit is contained in:
lila 2026-04-30 19:46:45 +02:00
parent 32ee1edf80
commit dc11213cb5
8 changed files with 41 additions and 79 deletions

View file

@ -4,7 +4,7 @@ import { authClient } from "../../lib/auth-client";
type Tab = "login" | "register";
type AuthModalProps = { onClose: () => void };
type AuthModalProps = { onClose: () => void; onSuccess: () => void };
type LoginFormProps = { onSuccess: () => void };
@ -142,11 +142,14 @@ const RegisterForm = ({ onSuccess }: RegisterFormProps) => {
);
};
const SocialButtons = () => {
type SocialButtonsProps = { onSuccess: () => void };
const SocialButtons = ({ onSuccess }: SocialButtonsProps) => {
const handleSocial = (provider: "google" | "github") => {
void authClient.signIn.social(
{ provider, callbackURL: window.location.origin },
{
onSuccess,
onError: (ctx) => {
toast.error(ctx.error.message ?? "Something went wrong.");
},
@ -179,7 +182,7 @@ const SocialButtons = () => {
);
};
export const AuthModal = ({ onClose }: AuthModalProps) => {
export const AuthModal = ({ onClose, onSuccess }: AuthModalProps) => {
const [tab, setTab] = useState<Tab>("login");
useEffect(() => {
@ -233,13 +236,13 @@ export const AuthModal = ({ onClose }: AuthModalProps) => {
</div>
{tab === "login" ? (
<LoginForm onSuccess={onClose} />
<LoginForm onSuccess={onSuccess} />
) : (
<RegisterForm onSuccess={onClose} />
)}
{/* Social */}
<SocialButtons />
<SocialButtons onSuccess={onSuccess} />
</div>
</div>
);