registration.js 746 B

12345678910111213141516171819202122232425
  1. async function register() {
  2. const response = await fetch('http://localhost:8000/api/auth/register', {
  3. method: 'POST',
  4. headers: {
  5. 'Content-Type': 'application/json',
  6. },
  7. body: JSON.stringify({
  8. name: document.getElementById('name').value,
  9. surname: document.getElementById('surname').value,
  10. phone_number: document.getElementById('phone').value,
  11. email: document.getElementById('email').value,
  12. password: document.getElementById('password').value
  13. })
  14. })
  15. const data = await response.json()
  16. if (!data.success) {
  17. return;
  18. }
  19. localStorage.setItem('token', data.token)
  20. window.location.href = 'mainPage.html'
  21. }