-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
218 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { useState } from "react"; | ||
|
||
const AuthForm = ({ onRegister, onLogin, onClose }) => { | ||
const [username, setUsername] = useState(""); | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [error, setError] = useState(""); | ||
const [isRegistering, setIsRegistering] = useState(true); | ||
|
||
const handleSubmit = (e) => { | ||
e.preventDefault(); | ||
if (isRegistering) { | ||
// Perform registration logic here | ||
const registerSuccess = onRegister(username, email, password); | ||
if (!registerSuccess) { | ||
setError("Registration failed. User already exists."); | ||
} | ||
} else { | ||
// Perform login logic here | ||
const loginSuccess = onLogin(username, password); | ||
if (!loginSuccess) { | ||
setError("Invalid credentials. Please try again."); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"> | ||
<div className="relative bg-white dark:bg-gray-800 rounded-lg p-6 w-full max-w-md"> | ||
<button | ||
className="absolute top-2 right-2 text-gray-600 dark:text-gray-300" | ||
onClick={onClose} | ||
> | ||
× | ||
</button> | ||
<h2 className="text-2xl font-bold mb-4 text-gray-800 dark:text-white"> | ||
{isRegistering ? "Register" : "Login"} | ||
</h2> | ||
{error && ( | ||
<div className="mb-4 p-2 text-red-700 bg-red-100 rounded-lg"> | ||
{error} | ||
</div> | ||
)} | ||
<form onSubmit={handleSubmit} className="auth-form"> | ||
<div className="mb-4"> | ||
<label htmlFor="username" className="block text-sm font-medium text-gray-700 dark:text-white"> | ||
Username: | ||
</label> | ||
<input | ||
type="text" | ||
id="username" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
required | ||
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white" | ||
/> | ||
</div> | ||
{isRegistering && ( | ||
<div className="mb-4"> | ||
<label htmlFor="email" className="block text-sm font-medium text-gray-700 dark:text-white"> | ||
Email: | ||
</label> | ||
<input | ||
type="email" | ||
id="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white" | ||
/> | ||
</div> | ||
)} | ||
<div className="mb-4"> | ||
<label htmlFor="password" className="block text-sm font-medium text-gray-700 dark:text-white"> | ||
Password: | ||
</label> | ||
<input | ||
type="password" | ||
id="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white" | ||
/> | ||
</div> | ||
<button | ||
type="submit" | ||
className="w-full rounded-lg bg-indigo-600 px-4 py-2 text-white transition-all duration-500 hover:bg-indigo-700 dark:bg-indigo-500 dark:hover:bg-indigo-600" | ||
> | ||
{isRegistering ? "Register" : "Login"} | ||
</button> | ||
</form> | ||
<div className="mt-4 text-center"> | ||
<button | ||
className="text-indigo-600 dark:text-indigo-400" | ||
onClick={() => setIsRegistering(!isRegistering)} | ||
> | ||
{isRegistering ? "Already have an account? Login" : "Don't have an account? Register"} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AuthForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "Akanbi-Bello Temidayo", | ||
"location": "Lagos, Nigeria", | ||
"bio": "A software developer who enjoys sharing his knowledge with others", | ||
"avatar": "https://github.com/Themydee", | ||
"portfolio": "https://themydee.vercel.app", | ||
"skills": ["React Native", "React", "Typescript", "JavaScript", "TailwindCss", "MySQL", "HTML", "CSS", "NodeJS, "], | ||
"social": { | ||
"GitHub": "https://github.comm/Themydee", | ||
"Twitter": "https://twitter.com/Themydee2001", | ||
"LinkedIn": "https://www.linkedin.com/in/akanbi-bello-temidayo" | ||
} | ||
} | ||
|