mirror of
https://github.com/Rushilwiz/rounded.git
synced 2025-04-09 22:00:18 -04:00
fix(client): changing from firebase auth to jwt
This commit is contained in:
parent
076139a82d
commit
c96ae5a316
|
@ -1,16 +1,32 @@
|
|||
import { useAuth } from "../lib/firebase/authContext";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
// import axios from "axios";
|
||||
export default function AuthComponent() {
|
||||
const { signup, signIn } = useAuth();
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState("");
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
async function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await signup(email, password);
|
||||
console.log(username);
|
||||
console.log(password);
|
||||
const requestOptions = {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
"username": username, //prettier-ignore
|
||||
"password": password, //prettier-ignore
|
||||
}),
|
||||
};
|
||||
|
||||
const response = await fetch("localhost:8000/api/token/", requestOptions);
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
|
||||
localStorage.setItem("token", data.access);
|
||||
|
||||
router.push("/");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
@ -20,7 +36,10 @@ export default function AuthComponent() {
|
|||
return (
|
||||
<>
|
||||
<h1>Register</h1>
|
||||
<input placeholder="Email" onChange={(e) => setEmail(e.target.value)} />
|
||||
<input
|
||||
placeholder="Email"
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
/>
|
||||
<input
|
||||
placeholder="Password"
|
||||
type="password"
|
||||
|
|
Loading…
Reference in New Issue
Block a user