Skip to content

Step 7 - Frontend for Signing up

Course: NextJS (Server side) - chapter 7

  1. Create app/signup/page.tsx
  2. Create a simple Page
import { Signup } from "@/components/Signup"
export default function() {
return <Signup />
}
  1. Create components/Signup.tsx
Code
$1b
  1. Convert components/Signup.tsx to a client component
"use client"
  1. Add a onclick handler that sends a POST request to /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>
  1. 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