11import { useState } from 'react'
22import * as z from 'zod'
3- import { json } from '@remix-run/node'
3+ import { data } from '@remix-run/node'
44import { Form , useActionData , Link } from '@remix-run/react'
55import { createUserSession , registerUser } from '~/utils/auth.server'
66import { usernameExists } from '~/utils/db.server'
@@ -22,14 +22,14 @@ export async function action({ request }: ActionFunctionArgs) {
2222 const formData = await request . formData ( )
2323 const formValues = Object . fromEntries ( formData )
2424 const results = formSchema . safeParse ( formValues )
25- if ( ! results . success ) return json ( { error : 'Invalid Data' } , { status : 400 } )
25+ if ( ! results . success ) return data ( { error : 'Invalid Data' } , { status : 400 } )
2626
2727 const { username, password } = results . data
2828 const userExists = await usernameExists ( username )
29- if ( userExists ) return json ( { error : 'Username already registered' } , { status : 400 } )
29+ if ( userExists ) return data ( { error : 'Username already registered' } , { status : 400 } )
3030
3131 const userId = await registerUser ( username , password )
32- if ( ! userId ) return json ( { error : 'We were not able to register this user' } , { status : 400 } )
32+ if ( ! userId ) return data ( { error : 'We were not able to register this user' } , { status : 400 } )
3333
3434 return createUserSession ( userId , '/' )
3535}
0 commit comments