From c96ae5a3166f0367c60fb5f1f1a42e73799de822 Mon Sep 17 00:00:00 2001 From: carraya Date: Sat, 16 Apr 2022 22:11:37 -0400 Subject: [PATCH] fix(client): changing from firebase auth to jwt --- client/src/common/components/Auth.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/client/src/common/components/Auth.js b/client/src/common/components/Auth.js index d202806..4e220fe 100644 --- a/client/src/common/components/Auth.js +++ b/client/src/common/components/Auth.js @@ -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 ( <>

Register

- setEmail(e.target.value)} /> + setUsername(e.target.value)} + />