1+ "use client"
2+
3+ import { signIn } from "next-auth/react"
4+ import { Button } from "@collax/ui/components/ui/button"
5+ import { useState } from "react"
6+ import Link from "next/link"
7+
8+ export default function SignUp ( ) {
9+ const [ email , setEmail ] = useState ( "" )
10+ const [ password , setPassword ] = useState ( "" )
11+ const [ name , setName ] = useState ( "" )
12+ const [ loading , setLoading ] = useState ( false )
13+
14+ const handleSignUp = async ( e : React . FormEvent ) => {
15+ e . preventDefault ( )
16+ setLoading ( true )
17+
18+ try {
19+ const response = await fetch ( "/api/auth/signup" , {
20+ method : "POST" ,
21+ headers : {
22+ "Content-Type" : "application/json" ,
23+ } ,
24+ body : JSON . stringify ( { email, password, name } ) ,
25+ } )
26+
27+ if ( response . ok ) {
28+ // Sign in after successful registration
29+ await signIn ( "credentials" , {
30+ email,
31+ password,
32+ callbackUrl : "/" ,
33+ } )
34+ } else {
35+ const data = await response . json ( )
36+ alert ( data . message || "Something went wrong" )
37+ }
38+ } catch {
39+ alert ( "Something went wrong" )
40+ } finally {
41+ setLoading ( false )
42+ }
43+ }
44+
45+ const handleGoogleSignIn = ( ) => {
46+ signIn ( "google" , { callbackUrl : "/" } )
47+ }
48+
49+ return (
50+ < div className = "min-h-screen flex items-center justify-center bg-gray-50" >
51+ < div className = "max-w-md w-full space-y-8" >
52+ < div >
53+ < h2 className = "mt-6 text-center text-3xl font-extrabold text-gray-900" >
54+ Create your account
55+ </ h2 >
56+ < p className = "mt-2 text-center text-sm text-gray-600" >
57+ Join Collax and start collaborating
58+ </ p >
59+ </ div >
60+ < div className = "mt-8 space-y-6" >
61+ < Button
62+ onClick = { handleGoogleSignIn }
63+ className = "w-full flex justify-center py-2 px-4"
64+ variant = "outline"
65+ >
66+ Sign up with Google
67+ </ Button >
68+
69+ < div className = "relative" >
70+ < div className = "absolute inset-0 flex items-center" >
71+ < div className = "w-full border-t border-gray-300" />
72+ </ div >
73+ < div className = "relative flex justify-center text-sm" >
74+ < span className = "px-2 bg-gray-50 text-gray-500" > Or continue with</ span >
75+ </ div >
76+ </ div >
77+
78+ < form className = "mt-8 space-y-6" onSubmit = { handleSignUp } >
79+ < div >
80+ < label htmlFor = "name" className = "sr-only" >
81+ Full name
82+ </ label >
83+ < input
84+ id = "name"
85+ name = "name"
86+ type = "text"
87+ autoComplete = "name"
88+ required
89+ className = "relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
90+ placeholder = "Full name"
91+ value = { name }
92+ onChange = { ( e ) => setName ( e . target . value ) }
93+ />
94+ </ div >
95+ < div >
96+ < label htmlFor = "email" className = "sr-only" >
97+ Email address
98+ </ label >
99+ < input
100+ id = "email"
101+ name = "email"
102+ type = "email"
103+ autoComplete = "email"
104+ required
105+ className = "relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
106+ placeholder = "Email address"
107+ value = { email }
108+ onChange = { ( e ) => setEmail ( e . target . value ) }
109+ />
110+ </ div >
111+ < div >
112+ < label htmlFor = "password" className = "sr-only" >
113+ Password
114+ </ label >
115+ < input
116+ id = "password"
117+ name = "password"
118+ type = "password"
119+ autoComplete = "new-password"
120+ required
121+ className = "relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
122+ placeholder = "Password"
123+ value = { password }
124+ onChange = { ( e ) => setPassword ( e . target . value ) }
125+ />
126+ </ div >
127+
128+ < div >
129+ < Button
130+ type = "submit"
131+ className = "w-full flex justify-center py-2 px-4"
132+ disabled = { loading }
133+ >
134+ { loading ? "Creating account..." : "Sign up" }
135+ </ Button >
136+ </ div >
137+
138+ < div className = "text-center" >
139+ < span className = "text-sm text-gray-600" >
140+ Already have an account?{ " " }
141+ < Link
142+ href = "/auth/signin"
143+ className = "font-medium text-indigo-600 hover:text-indigo-500"
144+ >
145+ Sign in
146+ </ Link >
147+ </ span >
148+ </ div >
149+ </ form >
150+ </ div >
151+ </ div >
152+ </ div >
153+ )
154+ }
0 commit comments