MCPcopy Create free account
hub / github.com/TanStack/db / handleSubmit

Function handleSubmit

examples/react/projects/src/routes/login.tsx:17–70  ·  view source on GitHub ↗
(e: FormEvent)

Source from the content-addressed store, hash-verified

15 const [currentError, setError] = useState(``)
16
17 const handleSubmit = async (e: FormEvent) => {
18 e.preventDefault()
19 setIsLoading(true)
20 setError(``)
21
22 try {
23 let { data, error } = await authClient.signUp.email(
24 {
25 email,
26 password,
27 name: email,
28 },
29 {
30 onSuccess: () => {
31 console.log(`signed up, navigating`)
32 window.location.href = `/`
33 },
34 }
35 )
36
37 if (error?.code === `USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL`) {
38 console.log(`user exists, logging in`)
39 const result = await authClient.signIn.email(
40 {
41 email,
42 password,
43 },
44 {
45 onSuccess: async () => {
46 console.log(`signed in, navigating`)
47 const { data: session, error: sessionError } =
48 await authClient.getSession()
49 console.log({ session, sessionError })
50 window.location.href = `/`
51 },
52 }
53 )
54
55 data = result.data
56 error = result.error
57 }
58
59 console.log({ data, error })
60
61 if (error) {
62 console.log(`set error`)
63 setError(JSON.stringify(error, null, 4))
64 }
65 } catch {
66 setError(`An unexpected error occurred`)
67 } finally {
68 setIsLoading(false)
69 }
70 }
71
72 return (
73 <div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected