Advertisement
metalni

Untitled

Jun 5th, 2023
1,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useState } from 'react'
  2. import { createUser } from 'src/services/data-service'
  3. import { useMutation } from '@tanstack/react-query'
  4. import { signIn } from 'next-auth/react'
  5. import { useRouter } from 'next/router'
  6.  
  7. const Test = () => {
  8.   const [email, setEmail] = useState('')
  9.   const [password, setPassword] = useState('')
  10.  
  11.   const router = useRouter()
  12.  
  13.   const createUserMutation = useMutation({
  14.     mutationFn: createUser,
  15.     mutationKey: createUser.queryKey,
  16.     onSuccess: async () => {
  17.       await signIn('credentials', { email, password })
  18.       await router.push('/gender') // TODO: Implement this screen
  19.     },
  20.   })
  21.  
  22.   const onSubmit = () => {
  23.     createUserMutation.mutate({ email, password })
  24.   }
  25.  
  26.   return (
  27.     <form onSubmit={onSubmit}>
  28.       <input value={email} onChange={(e) => setEmail(e.target.value)} />
  29.       <input value={password} onChange={(e) => setPassword(e.target.value)} />
  30.       <button>Submit</button>
  31.     </form>
  32.   )
  33. }
  34.  
  35. export default Test
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement