11"use client" ;
22
33import { AuthHook } from "@/components/hooks/auth-hook" ;
4+ import { authenticationSchema , authSchemas } from "@/lib/typebox/auth" ;
45import Link from "next/link" ;
56import { useRouter } from "next/navigation" ;
67import { FormEvent , useState } from "react" ;
78
8- interface RegisterPageProps { }
9-
10- export default function RegisterPage ( props : RegisterPageProps ) {
9+ export default function RegisterPage ( ) {
1110 const router = useRouter ( ) ;
1211 const { registerMutation } = AuthHook ( ) ;
1312 const [ status , setStatus ] = useState ( "" ) ;
@@ -21,7 +20,7 @@ export default function RegisterPage(props: RegisterPageProps) {
2120 username,
2221 password,
2322 } )
24- . then ( ( user ) => ( user ? router . push ( "/dashboard" ) : setStatus ( user ) ) )
23+ . then ( ( ) => router . push ( "/dashboard" ) )
2524 . catch ( ( error ) => setStatus ( JSON . stringify ( error ) ) ) ;
2625 } ;
2726
@@ -34,7 +33,10 @@ export default function RegisterPage(props: RegisterPageProps) {
3433 type = "text"
3534 value = { username }
3635 onChange = { ( e ) => setUsername ( e . target . value ) }
36+ minLength = { authenticationSchema . properties . username . minLength }
37+ maxLength = { authenticationSchema . properties . username . maxLength }
3738 required
39+ autoComplete = "username"
3840 />
3941 </ div >
4042 < div className = "flex flex-col border" >
@@ -43,12 +45,25 @@ export default function RegisterPage(props: RegisterPageProps) {
4345 id = "password"
4446 type = "password"
4547 value = { password }
48+ minLength = { authenticationSchema . properties . password . minLength }
49+ maxLength = { authenticationSchema . properties . password . maxLength }
4650 onChange = { ( e ) => setPassword ( e . target . value ) }
4751 required
52+ autoComplete = "current-password"
4853 />
4954 </ div >
5055 < div className = "flex justify-between" >
51- < button className = "bg-red-600" type = "submit" >
56+ < button
57+ className = "bg-red-600 disabled:bg-gray-600"
58+ type = "submit"
59+ disabled = {
60+ registerMutation . isPending ||
61+ ! authSchemas . authUser . safeParse ( {
62+ username,
63+ password,
64+ } ) . success
65+ }
66+ >
5267 Register
5368 </ button >
5469
0 commit comments