-
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(auth): add possibility to register new users
- Loading branch information
1 parent
7218853
commit bc06a27
Showing
7 changed files
with
133 additions
and
46 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 |
---|---|---|
|
@@ -4,7 +4,3 @@ | |
/* justify-content: center; */ | ||
/* align-items: center; */ | ||
/* } */ | ||
|
||
main { | ||
padding-top: 80px; | ||
} |
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,9 @@ | ||
main { | ||
padding-top: 60px; | ||
} | ||
|
||
form { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
} |
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 was deleted.
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,65 @@ | ||
import { useNavigate } from "react-router-dom"; | ||
import { useAuth } from "../hooks/useAuth"; | ||
import { FormEvent, useState } from "react"; | ||
import { Alert, Button, Container, TextField } from "@mui/material"; | ||
import { AppwriteException } from "appwrite"; | ||
|
||
export function Register() { | ||
const navigate = useNavigate(); | ||
const auth = useAuth(); | ||
|
||
const [email, setEmail] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
const [name, setName] = useState(""); | ||
|
||
const [err, setErr] = useState<string | undefined>(); | ||
|
||
function onSubmit(e: FormEvent) { | ||
e.preventDefault(); | ||
auth | ||
.register(email, password, name) | ||
.then(() => { | ||
navigate("/"); | ||
}) | ||
.catch((e: AppwriteException | unknown) => { | ||
if (e instanceof AppwriteException) { | ||
setErr(e.message); | ||
} | ||
console.log(e); | ||
}); | ||
} | ||
|
||
return ( | ||
<Container maxWidth="sm"> | ||
<h2>Register</h2> | ||
<form onSubmit={onSubmit}> | ||
{err && <Alert severity="error">{err}</Alert>} | ||
<TextField | ||
type="text" | ||
name="username" | ||
value={name} | ||
onChange={(e) => setName(e.target.value)} | ||
variant="standard" | ||
label="Username" | ||
/> | ||
<TextField | ||
type="email" | ||
name="email" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
variant="standard" | ||
label="EMail" | ||
/> | ||
<TextField | ||
type="password" | ||
name="password" | ||
label="Password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
variant="standard" | ||
/> | ||
<Button type="submit">Register</Button> | ||
</form> | ||
</Container> | ||
); | ||
} |