-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
07aad9d
commit 31af227
Showing
12 changed files
with
257 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,25 @@ | ||
import React from "react"; | ||
import { Link } from "react-router-dom"; | ||
|
||
const HomePage = () => { | ||
return ( | ||
<div className="flex flex-col items-center justify-center h-screen bg-blue-100"> | ||
<div className="flex space-x-4"> | ||
<Link | ||
to="/login" | ||
className="px-4 py-2 bg-blue-500 text-white rounded shadow" | ||
> | ||
Login | ||
</Link> | ||
<Link | ||
to="/register" | ||
className="px-4 py-2 bg-green-500 text-white rounded shadow" | ||
> | ||
Register | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default HomePage; |
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,42 @@ | ||
import React, { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useDispatch } from "react-redux"; | ||
import { login } from "../redux/operations"; | ||
|
||
const LoginPage = () => { | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const dispatch = useDispatch(); | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
dispatch(login({ email, password })) | ||
.then(() => navigate("/")) | ||
.catch((error) => console.log(error)); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<label> | ||
Email: | ||
<input | ||
type="email" | ||
value={email} | ||
onChange={(event) => setEmail(event.target.value)} | ||
/> | ||
</label> | ||
<label> | ||
Password: | ||
<input | ||
type="password" | ||
value={password} | ||
onChange={(event) => setPassword(event.target.value)} | ||
/> | ||
</label> | ||
<button type="submit">Login</button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default LoginPage; |
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,10 @@ | ||
import { Navigate } from "react-router-dom"; | ||
import { useSelector } from "react-redux"; | ||
import { selectIsAuthenticated } from "../redux/selectors"; | ||
|
||
const PrivateRoute = ({ children }) => { | ||
const isAuthenticated = useSelector(selectIsAuthenticated); | ||
return isAuthenticated ? children : <Navigate to="/login" />; | ||
}; | ||
|
||
export default PrivateRoute; |
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,54 @@ | ||
import React, { useState } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
import { register } from "../redux/operations"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
const RegisterPage = () => { | ||
const [name, setName] = useState(""); | ||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const dispatch = useDispatch(); | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
dispatch(register({ name, email, password })) | ||
.then(() => navigate("/")) | ||
.catch((error) => console.error("Failed to register:", error)); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<label> | ||
Name: | ||
<input | ||
type="text" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
required | ||
/> | ||
</label> | ||
<label> | ||
Email: | ||
<input | ||
type="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
/> | ||
</label> | ||
<label> | ||
Password: | ||
<input | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
/> | ||
</label> | ||
<button type="submit">Register</button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default RegisterPage; |
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,10 @@ | ||
import { Navigate } from "react-router-dom"; | ||
import { useSelector } from "react-redux"; | ||
import { selectIsAuthenticated } from "../redux/selectors"; | ||
|
||
const RestrictedRoute = ({ children }) => { | ||
const isAuthenticated = useSelector(selectIsAuthenticated); | ||
return isAuthenticated ? <Navigate to="/" /> : children; | ||
}; | ||
|
||
export default RestrictedRoute; |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
import { Provider } from "react-redux"; | ||
|
||
import "./index.css"; | ||
|
||
import App from "./components/App"; | ||
|
||
import { store } from "./redux/store"; | ||
import "./index.css"; | ||
|
||
ReactDOM.createRoot(document.getElementById("root")).render( | ||
<React.StrictMode> | ||
<Provider store={store}> | ||
<App /> | ||
<BrowserRouter> | ||
<App /> | ||
</BrowserRouter> | ||
</Provider> | ||
</React.StrictMode> | ||
); |
Oops, something went wrong.