From 0cbf0edd1557f6676e779da7a010535126824b3e Mon Sep 17 00:00:00 2001 From: Leo dev Date: Mon, 29 Sep 2025 12:34:49 +0200 Subject: [PATCH] Sign up --- src/app/signup/page.tsx | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/app/signup/page.tsx diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx new file mode 100644 index 0000000..4745b66 --- /dev/null +++ b/src/app/signup/page.tsx @@ -0,0 +1,57 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import axios from "axios"; +import { useState } from "react"; +import Cookies from "js-cookie"; +import { redirect } from "next/navigation"; + +export default function SignUp() { + const [username, setUsername] = useState(""); + const [email, setEmail] = useState(""); + const [password, setPassword] = useState(""); + + const signup = async () => { + const res = await axios.post("/api/user", { username, password, email }); + Cookies.set("token", (res.data as any).token); + redirect("/"); + }; + + return ( +
+
+

Sign Up

+ + Email + setEmail(e.target.value)} + placeholder={"john@example.com"} + type="email" + /> + + + Username + setUsername(e.target.value)} + placeholder={"john"} + /> + + + Password + setPassword(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") signup(); + }} + type="password" + /> + + + +
+
+ ); +}