-
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.
feat: add basic login and logout functionality
- Loading branch information
1 parent
0fd1da7
commit 2fdf5b3
Showing
11 changed files
with
618 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
main { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} |
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,18 @@ | ||
nav { | ||
/* border: 1px solid black; */ | ||
|
||
display: flex; | ||
justify-content: space-between; | ||
margin: 5px; | ||
padding: 10px; | ||
box-shadow: 0px 0px 32px 0px #999; | ||
border-radius: 5px; | ||
|
||
ul { | ||
display: flex; | ||
list-style: none; | ||
gap: 10px; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} |
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,16 @@ | ||
import { useAuth } from "../hooks/useAuth"; | ||
import "./navbar.css"; | ||
|
||
export function NavBar() { | ||
const { user, logout } = useAuth(); | ||
return ( | ||
<nav> | ||
<ul> | ||
<li>Home</li> | ||
<li>Page</li> | ||
</ul> | ||
<span>{user?.name ?? "FUCK"}</span> | ||
<button onClick={() => logout()}>Logout</button> | ||
</nav> | ||
); | ||
} |
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,6 @@ | ||
import { useContext } from "react"; | ||
import { AuthContext } from "../contexts/auth"; | ||
|
||
export function useAuth() { | ||
return useContext(AuthContext); | ||
} |
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,11 @@ | ||
.login-form { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
|
||
input { | ||
padding: 5px; | ||
border: 1px solid #42423d; | ||
border-radius: 5px; | ||
} | ||
} |
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,40 @@ | ||
import { FormEvent, useState } from "react"; | ||
|
||
import "./login.css"; | ||
import { useAuth } from "../hooks/useAuth"; | ||
|
||
export function Login() { | ||
const auth = useAuth(); | ||
|
||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
function onSubmit(e: FormEvent<HTMLFormElement>) { | ||
e.preventDefault(); | ||
|
||
auth.login(username, password).then(console.log).catch(console.error); | ||
} | ||
|
||
return ( | ||
<> | ||
<h2>Login</h2> | ||
<form onSubmit={onSubmit} className="login-form"> | ||
<input | ||
type="email" | ||
name="username" | ||
placeholder="Username" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
/> | ||
<input | ||
type="password" | ||
name="password" | ||
placeholder="Password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
/> | ||
<button>Login</button> | ||
</form> | ||
</> | ||
); | ||
} |
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,19 @@ | ||
import { NavBar } from "../components/navbar"; | ||
import { useAuth } from "../hooks/useAuth"; | ||
import { Login } from "./login"; | ||
|
||
export function Page() { | ||
const { loggedIn } = useAuth(); | ||
return ( | ||
<main> | ||
<h1>Kneipolympics</h1> | ||
{loggedIn ? ( | ||
<> | ||
<NavBar></NavBar> | ||
</> | ||
) : ( | ||
<Login></Login> | ||
)} | ||
</main> | ||
); | ||
} |