diff --git a/client/src/common/components/Auth.js b/client/src/common/components/Auth.js index ded1042..c03b10b 100644 --- a/client/src/common/components/Auth.js +++ b/client/src/common/components/Auth.js @@ -7,7 +7,29 @@ export default function AuthComponent() { const router = useRouter(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); + const [registerUsername, setRegisterUsername] = useState(""); + const [registerPassword, setRegisterPassword] = useState(""); + async function handleRegisterSubmit(e) { + try { + const requestOptions = { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + username: registerUsername, + password: registerPassword, + }), + }; + const response = await fetch( + "http://localhost:8000/api/profile/create", + requestOptions + ); + const dataa = await response.json(); + console.log(dataa); + } catch (error) { + console.log(error); + } + } async function handleSubmit(e) { try { console.log(username); @@ -29,6 +51,18 @@ export default function AuthComponent() { console.log(data); localStorage.setItem("token", data.access); + localStorage.setItem("username", username); + + // const reqOps = { + // method: "GET", + // headers: { + // "Content-Type": "application/json", + // Authorization: `Bearer ${data.access}`, + // }, + // }; + // const resp = await fetch("http://localhost:8000/api/foundation/", reqOps); + // const data2 = await resp.json(); + // console.log(data2); router.push("/"); } catch (error) { @@ -38,9 +72,9 @@ export default function AuthComponent() { return ( <> -
This page is under construction. Please check back later.
+ {/* {foundation.map((item) => ( +You're logged in! Current email: {currentUser.email}
+ {localStorage.getItem("username") ? ( ++ You're logged in! Current username: {localStorage.getItem("username")} +
) : (Not logged in
)} diff --git a/client/src/pages/profile.js b/client/src/pages/profile.js new file mode 100644 index 0000000..7dc1343 --- /dev/null +++ b/client/src/pages/profile.js @@ -0,0 +1,37 @@ +import { useState } from "react"; +export default function Profile() { + const [wallet, setWallet] = useState(""); + async function handleSubmit(e) { + try { + const reqOps = { + method: "POST", + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${localStorage.getItem("token")}`, //prettier-ignore + }, + body: { + "address": wallet, //prettier-ignore + }, + }; + const resp = await fetch( + "http://localhost:8000/api/profile/add_wallet", + reqOps + ); + const data = await resp.json(); + console.log(data); + } catch (error) { + console.log(error); + } + } + return ( +