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

Function Layout

examples/react/projects/src/routes/login.tsx:11–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9})
10
11function Layout() {
12 const [email, setEmail] = useState(``)
13 const [password, setPassword] = useState(``)
14 const [isLoading, setIsLoading] = useState(false)
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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected