Download AuthForm.tsx from Akshat394/STUDIO_AI: direct link, hf CLI and curl.
- Browser
- Download file 5.79 kB
-
https://huggingface.co/spaces/Akshat394/STUDIO_AI/resolve/main/AuthForm.tsx
- Command line
-
hf download hf://spaces/Akshat394/STUDIO_AI/AuthForm.tsx
-
curl -L -o AuthForm.tsx https://huggingface.co/spaces/Akshat394/STUDIO_AI/resolve/main/AuthForm.tsx
5.79 kB
| import React, { useState } from "react"; | |
| // import { useNavigate } from "react-router-dom"; // Removed unused import | |
| import { Button } from "@/components/ui/button"; | |
| import { Input } from "@/components/ui/input"; | |
| interface AuthFormProps { | |
| view: "login" | "signup"; | |
| setView: React.Dispatch<React.SetStateAction<"login" | "signup">>; | |
| } | |
| const AuthForm: React.FC<AuthFormProps> = ({ view, setView }) => { | |
| const [email, setEmail] = useState(""); | |
| const [password, setPassword] = useState(""); | |
| const [loading, setLoading] = useState(false); | |
| const [err, setErr] = useState<string | null>(null); | |
| const handleAuth = async (e: React.FormEvent) => { | |
| e.preventDefault(); | |
| setLoading(true); | |
| setErr(null); | |
| if (!email || !password) { | |
| setErr("Please enter email and password"); | |
| setLoading(false); | |
| return; | |
| } | |
| // Removed Supabase authentication logic for UI review | |
| // if (view === "login") { | |
| // const { error } = await supabase.auth.signInWithPassword({ email, password }); | |
| // if (error) { | |
| // setErr( | |
| // error.message === "Invalid login credentials" | |
| // ? "Invalid email or password." | |
| // : error.message | |
| // ); | |
| // } else { | |
| // navigate("/"); | |
| // } | |
| // } else { | |
| // const { error } = await supabase.auth.signUp({ | |
| // email, | |
| // password, | |
| // options: { emailRedirectTo: window.location.origin + "/" }, | |
| // }); | |
| // if (error) { | |
| // setErr(error.message); | |
| // } else { | |
| // setErr("Check your email for a confirmation link!"); | |
| // } | |
| // } | |
| setLoading(false); | |
| }; | |
| return ( | |
| <> | |
| <form onSubmit={handleAuth} className="space-y-4 mt-2"> | |
| <Input | |
| autoFocus | |
| type="email" | |
| placeholder="Email" | |
| value={email} | |
| autoComplete="username" | |
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => setEmail(e.target.value)} | |
| disabled={loading} | |
| className="focus:ring-2 focus:ring-[#7f7fd5] focus:border-[#38f9d7] | |
| bg-gradient-to-tr from-[#fff] via-[#38f9d7]/20 to-[#ffd200]/20 | |
| border-2 border-[#38f9d7]/50 | |
| text-[#19142a] dark:text-white | |
| placeholder:text-muted-foreground font-semibold | |
| transition-all shadow-lg shadow-[#38f9d7]/10 | |
| " | |
| /> | |
| <Input | |
| type="password" | |
| placeholder="Password" | |
| value={password} | |
| autoComplete={view === "login" ? "current-password" : "new-password"} | |
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => setPassword(e.target.value)} | |
| disabled={loading} | |
| className="focus:ring-2 focus:ring-[#ffd200] focus:border-[#f7971e] | |
| bg-gradient-to-br from-[#fff] via-[#38f9d7]/10 to-[#f7971e]/20 | |
| border-2 border-[#ffd200]/60 | |
| text-[#19142a] dark:text-white | |
| placeholder:text-muted-foreground font-semibold | |
| transition-all shadow-lg shadow-[#ffd200]/10 | |
| " | |
| /> | |
| {err && ( | |
| <p className="text-destructive text-base text-center font-semibold px-2" aria-live="polite"> | |
| {err} | |
| </p> | |
| )} | |
| <Button | |
| className="w-full mt-1 bg-gradient-to-r from-[#7f7fd5] via-[#38f9d7] to-[#f7971e] text-white font-bold shadow-md | |
| hover:bg-gradient-to-br hover:from-[#f7971e] hover:via-[#38f9d7] hover:to-[#7f7fd5] transition-all duration-150" | |
| variant="default" | |
| type="submit" | |
| disabled={loading} | |
| > | |
| {loading ? "Please wait..." : view === "login" ? "Sign In" : "Sign Up"} | |
| </Button> | |
| </form> | |
| <div className="text-center text-base mt-2"> | |
| {view === "login" ? ( | |
| <> | |
| <span className="text-slate-300 dark:text-slate-200">New here? </span> | |
| <span | |
| className="font-bold underline underline-offset-4 text-[#43e97b] bg-gradient-to-r from-[#ffd200] via-[#38f9d7] to-[#f7971e] bg-clip-text text-transparent | |
| shadow-sm | |
| hover:text-[#ffd200] hover:bg-none | |
| focus:outline focus:outline-2 focus:outline-[#38f9d7] | |
| cursor-pointer transition-all duration-150 | |
| px-1 | |
| " | |
| onClick={() => { setView("signup"); setErr(null); }} | |
| tabIndex={0} | |
| role="button" | |
| aria-label="Create an account" | |
| onKeyDown={e => { if (e.key === "Enter" || e.key === " ") { setView("signup"); setErr(null); } }} | |
| > | |
| Create an account | |
| </span> | |
| </> | |
| ) : ( | |
| <> | |
| <span className="text-slate-300 dark:text-slate-200">Already have an account? </span> | |
| <span | |
| className="font-bold underline underline-offset-4 text-[#38f9d7] bg-gradient-to-r from-[#f7971e] via-[#38f9d7] to-[#7f7fd5] bg-clip-text text-transparent | |
| shadow-sm | |
| hover:text-[#7f7fd5] hover:bg-none | |
| focus:outline focus:outline-2 focus:outline-[#38f9d7] | |
| cursor-pointer transition-all duration-150 | |
| px-1 | |
| " | |
| onClick={() => { setView("login"); setErr(null); }} | |
| tabIndex={0} | |
| role="button" | |
| aria-label="Sign in" | |
| onKeyDown={e => { if (e.key === "Enter" || e.key === " ") { setView("login"); setErr(null); } }} | |
| > | |
| Sign in | |
| </span> | |
| </> | |
| )} | |
| </div> | |
| </> | |
| ); | |
| }; | |
| export default AuthForm; |