Download frontend/src/components/AuthScreen.jsx from bhuvi3/CIOAgent: direct link, hf CLI and curl.
- Browser
- Download file 3.66 kB
-
https://huggingface.co/spaces/bhuvi3/CIOAgent/resolve/main/frontend/src/components/AuthScreen.jsx
- Command line
-
hf download hf://spaces/bhuvi3/CIOAgent/frontend/src/components/AuthScreen.jsx
-
curl -L -o AuthScreen.jsx https://huggingface.co/spaces/bhuvi3/CIOAgent/resolve/main/frontend/src/components/AuthScreen.jsx
3.66 kB
| import React, { useState } from "react"; | |
| export default function AuthScreen({ onAuth }) { | |
| const [mode, setMode] = useState("login"); | |
| const [username, setUsername] = useState(""); | |
| const [password, setPassword] = useState(""); | |
| const [confirmPassword, setConfirmPassword] = useState(""); | |
| const [error, setError] = useState(""); | |
| const [loading, setLoading] = useState(false); | |
| const submit = async (e) => { | |
| e.preventDefault(); | |
| setError(""); | |
| if (!username.trim()) { | |
| setError("Username is required."); | |
| return; | |
| } | |
| if (password.length < 4) { | |
| setError("Password must be at least 4 characters."); | |
| return; | |
| } | |
| if (mode === "signup" && password !== confirmPassword) { | |
| setError("Passwords do not match."); | |
| return; | |
| } | |
| setLoading(true); | |
| try { | |
| const endpoint = mode === "login" ? "/auth/login" : "/auth/signup"; | |
| const res = await fetch(endpoint, { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ username: username.trim(), password }), | |
| }); | |
| if (!res.ok) { | |
| const data = await res.json(); | |
| throw new Error(data.detail || "Authentication failed."); | |
| } | |
| const data = await res.json(); | |
| onAuth(data.token, data.username); | |
| } catch (err) { | |
| setError(err.message); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| return ( | |
| <div className="auth-backdrop"> | |
| <div className="auth-card"> | |
| <h1 className="auth-title">Portfolio CIO</h1> | |
| <p className="auth-subtitle"> | |
| {mode === "login" ? "Sign in to your account" : "Create a new account"} | |
| </p> | |
| {error && <div className="auth-error">{error}</div>} | |
| <form onSubmit={submit} className="auth-form"> | |
| <label>Username</label> | |
| <input | |
| type="text" | |
| value={username} | |
| onChange={(e) => setUsername(e.target.value)} | |
| placeholder="Enter username" | |
| autoFocus | |
| /> | |
| <label>Password</label> | |
| <input | |
| type="password" | |
| value={password} | |
| onChange={(e) => setPassword(e.target.value)} | |
| placeholder="Enter password" | |
| /> | |
| {mode === "signup" && ( | |
| <> | |
| <label>Confirm Password</label> | |
| <input | |
| type="password" | |
| value={confirmPassword} | |
| onChange={(e) => setConfirmPassword(e.target.value)} | |
| placeholder="Confirm password" | |
| /> | |
| </> | |
| )} | |
| <button type="submit" className="btn primary auth-btn" disabled={loading}> | |
| {loading | |
| ? "Please wait..." | |
| : mode === "login" | |
| ? "Sign In" | |
| : "Sign Up"} | |
| </button> | |
| </form> | |
| <p className="auth-toggle"> | |
| {mode === "login" ? ( | |
| <> | |
| Don't have an account?{" "} | |
| <button | |
| className="auth-link" | |
| onClick={() => { | |
| setMode("signup"); | |
| setError(""); | |
| }} | |
| > | |
| Sign Up | |
| </button> | |
| </> | |
| ) : ( | |
| <> | |
| Already have an account?{" "} | |
| <button | |
| className="auth-link" | |
| onClick={() => { | |
| setMode("login"); | |
| setError(""); | |
| }} | |
| > | |
| Sign In | |
| </button> | |
| </> | |
| )} | |
| </p> | |
| </div> | |
| </div> | |
| ); | |
| } | |