Step 7 - Frontend for Signing up
Course: NextJS (Server side) - chapter 7
- Create
app/signup/page.tsx - Create a simple Page
import { Signup } from "@/components/Signup"
export default function() { return <Signup />}- Create
components/Signup.tsx
Code
$1b- Convert
components/Signup.tsxto a client component
"use client"- Add a
onclick handlerthat sends aPOST requestto/user
<button onClick={async () => { const response = await axios.post("http://localhost:3000/api/user", { username, password });
}} type="button" className="mt-8 w-full text-white bg-gray-800 focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2">Sign in</button>- Route the user to landing page if the signup succeeded Ref useRouter hook - https://nextjs.org/docs/app/building-your-application/routing/linking-and-navigating#userouter-hook
Final signup.tsx
$1d💡 We still have to implement the backend route, lets do that in the next slide