"use client"; import { FormState, postLogin, postRegister } from "@/actions/login"; import { useActionState, useEffect, useState } from "react"; import { Card, CardHeader, CardDescription, CardContent, CardFooter, CardTitle, } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; export default function AuthScreen() { const [isReg, setReg] = useState(false); return setReg((b) => !b)} />; } function OOldform({ isReg, toggle }: { isReg: boolean; toggle: () => void }) { const regstrings = { title: "Welcome to Sorlang", desc: "Sign up", button: "Sign up", toggle: "Have an account?", toggle2: "Login", }; const logstrings = { title: "Welcome back", desc: "Login to Sorlang", button: "Login", toggle: "Don't have an account?", toggle2: "Sign up", }; const [strings, setStrings] = useState(logstrings); useEffect(() => { if (isReg) setStrings(regstrings); else setStrings(logstrings); }, [isReg]); const [state, formAction, isPending] = useActionState( isReg ? postRegister : postLogin, { error: "" }, "/login", ); console.log({ state }); // Handle redirect after successful login if (state.success && state.redirect) { window.location.href = state.redirect; } return (
{strings.title} {strings.desc}
{strings.toggle} {strings.toggle2}
{state.error &&

{state.error}

} {state.success &&

Login successful! Redirecting...

}
By clicking continue, you agree to our{" "} Terms of Service and Privacy Policy.
//
// {state.msg} // // // //
// Don't have an account?{" "} // // Sign up // //
//
); }