@@ -15,7 +15,7 @@ import {
1515 useLoginOptions ,
1616 useUserInvalidate ,
1717} from "@lib/hooks" ;
18- import { useState } from "react" ;
18+ import { type FormEvent } from "react" ;
1919import { ThemeToggle } from "@ui/theme" ;
2020import { KOMODO_BASE_URL } from "@main" ;
2121import { KeyRound , X } from "lucide-react" ;
@@ -38,7 +38,6 @@ const login_with_oauth = (provider: OauthProvider) => {
3838
3939export default function Login ( ) {
4040 const options = useLoginOptions ( ) . data ;
41- const [ creds , set ] = useState ( { username : "" , password : "" } ) ;
4241 const userInvalidate = useUserInvalidate ( ) ;
4342 const { toast } = useToast ( ) ;
4443
@@ -98,7 +97,18 @@ export default function Login() {
9897 } ,
9998 } ) ;
10099
101-
100+ const handleSubmit = ( e : FormEvent < HTMLFormElement > ) => {
101+ e . preventDefault ( ) ;
102+ const fd = new FormData ( e . currentTarget ) ;
103+ const username = String ( fd . get ( "username" ) ?? "" ) ;
104+ const password = String ( fd . get ( "password" ) ?? "" ) ;
105+ const action = String ( fd . get ( "action" ) ?? "login" ) ;
106+ if ( action === "signup" ) {
107+ signup ( { username, password } ) ;
108+ } else {
109+ login ( { username, password } ) ;
110+ }
111+ } ;
102112
103113 const no_auth_configured =
104114 options !== undefined &&
@@ -110,7 +120,6 @@ export default function Login() {
110120 return (
111121 < div className = "flex flex-col min-h-screen" >
112122 < div className = "container flex justify-end items-center h-16" >
113- { /* <img src="/komodo-512x512.png" className="w-[32px]" /> */ }
114123 < ThemeToggle />
115124 </ div >
116125 < div
@@ -166,63 +175,66 @@ export default function Login() {
166175 </ div >
167176 </ CardHeader >
168177 { options ?. local && (
169- < >
178+ < form
179+ onSubmit = { handleSubmit }
180+ autoComplete = "on"
181+ >
170182 < CardContent className = "flex flex-col justify-center w-full gap-4" >
171183 < div className = "flex flex-col gap-2" >
172184 < Label htmlFor = "username" > Username</ Label >
173185 < Input
174186 id = "username"
175- value = { creds . username }
176- onChange = { ( { target } ) =>
177- set ( ( c ) => ( { ... c , username : target . value } ) )
178- }
187+ name = " username"
188+ autoComplete = "username"
189+ autoCapitalize = "none"
190+ autoCorrect = "off"
179191 />
180192 </ div >
181193 < div className = "flex flex-col gap-2" >
182194 < Label htmlFor = "password" > Password</ Label >
183195 < Input
184196 id = "password"
197+ name = "password"
185198 type = "password"
186- value = { creds . password }
187- onChange = { ( { target } ) =>
188- set ( ( c ) => ( { ...c , password : target . value } ) )
189- }
190- onKeyDown = { ( e ) => e . key === "Enter" && login ( creds ) }
199+ autoComplete = "current-password"
191200 />
192201 </ div >
193202 </ CardContent >
194203 < CardFooter className = "flex gap-4 w-full justify-end" >
195204 { show_sign_up && (
196205 < Button
197206 variant = "outline"
198- onClick = { ( ) => signup ( creds ) }
207+ type = "submit"
208+ name = "action"
209+ value = "signup"
199210 disabled = { signupPending }
200211 >
201212 Sign Up
202213 </ Button >
203214 ) }
204215 < Button
205216 variant = "default"
206- onClick = { ( ) => login ( creds ) }
217+ type = "submit"
218+ name = "action"
219+ value = "login"
207220 disabled = { loginPending }
208221 >
209222 Log In
210223 </ Button >
211224 </ CardFooter >
212- </ >
225+ </ form >
213226 ) }
214227 { no_auth_configured && (
215228 < CardContent className = "w-full gap-2 text-muted-foreground text-sm" >
216229 No login methods have been configured. See the
217- < Button variant = "link" className = "text-sm py-0 px-1" >
218- < a
219- href = "https://github.com/moghtech/komodo/blob/main/config/core.config.toml"
220- target = "_blank"
221- className = "flex text-sm"
222- >
223- example config
224- </ a >
225- </ Button >
230+ < a
231+ href = "https://github.com/moghtech/komodo/blob/main/config/core.config.toml"
232+ target = "_blank"
233+ rel = "noreferrer"
234+ className = "text-sm py-0 px-1 underline"
235+ >
236+ example config
237+ </ a >
226238 for information on configuring auth.
227239 </ CardContent >
228240 ) }
0 commit comments