title: React registraion
body: <p>I`m new in react, and I get problem with registration:</p>
  
  <p>http.hook.js:17 POST <a href="http://localhost:3000/api/auth/register" rel="nofollow noreferrer">http://localhost:3000/api/auth/register</a> 500 (Internal Server Error)</p>
  
  <p>Error: Что-то пошло не так :(, попробуйте снова
      at http.hook.js:21
      at async registerHandler (Registration.js:24)</p>
  
  <p>code http.hook.js :</p>
  
  <pre><code>import {useState, useCallback} from 'react';
  
  export const useHttp = () =&gt; {
      const [loading, setLoading] = useState(false);
      const [error, setError] = useState(null);
  
  
      const request = useCallback( async (url, method = 'GET', body = null, headers = {}) =&gt; {
          setLoading(true);
          try {
  
              if (body) {
                  body = JSON.stringify(body);
                  headers['Content-Type'] = 'application/json'
              }
  
              const response = await fetch(url, {method, body, headers});
              const data = await response.json();
  
              if (!response.ok) {
                  throw new Error(data.message || 'Что-то пошло не так :(');
              };
  
              setLoading(false);
  
              return data;
          } catch (e) {
              console.log(e)
              setLoading(false);
              setError(e.message);
              throw e;
          }
      }, [])
  
      const clearError = useCallback( () =&gt; setError(null), []);
  
      return { loading, request, error, clearError }
  }
  </code></pre>
  
  <p>and code Registration.js without front-end:</p>
  
  <pre><code>import React, { useState, useEffect } from 'react';
  import { useHttp } from '../hooks/http.hook';
  import { useMessage } from '../hooks/message.hook';
  
  export const Registration = () =&gt; {
      const message = useMessage();
      const {loading, error, request, clearError} = useHttp();
      const [form, setForm] = useState({
          nick: '', email: '', password:''
      });
  
      useEffect(() =&gt; {
          console.log(error);
          message(error);
          clearError();
      }, [error, message, clearError]);
  
      const changeHandler = event =&gt; {
          setForm({ ...form, [event.target.name]: event.target.value });
      };
  
      const registerHandler = async () =&gt; {
          try {
              const data = await request('/api/auth/register', 'POST', {...form});
              console.log('Data', data)
          } catch (e) {
              console.log(e)
          }
      };
  </code></pre>