fix(client): changing from firebase auth to jwt

This commit is contained in:
carraya 2022-04-16 22:11:37 -04:00
parent 076139a82d
commit c96ae5a316

View File

@ -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"