public/javascript/signup.js
// create js to enable users to sign up
create js to enable users to sign up
create js to enable users to sign up
async function signupFormHandler(event) {
    event.preventDefault();
    const username = document.querySelector('#username-signup').value.trim();
    const email = document.querySelector('#email-signup').value.trim();
    const password = document.querySelector('#password-signup').value.trim();
    const github = document.querySelector('#github-signup').value.trim();
    if (username && email && password) {
      const response = await fetch('/api/users', {
        method: 'post',
        body: JSON.stringify({
          username,
          email,
          github,
          password
        }),
        headers: { 'Content-Type': 'application/json' }
      });
      if (response.ok) {
        console.log('success');
        document.location.replace('/dashboard');
      } else {
        alert(response.statusText);
      }
    }
}
async function signupFormHandler ( event ) { event . preventDefault ( ) ; const username = document . querySelector ( '#username-signup' ) . value . trim ( ) ; const email = document . querySelector ( '#email-signup' ) . value . trim ( ) ; const password = document . querySelector ( '#password-signup' ) . value . trim ( ) ; const github = document . querySelector ( '#github-signup' ) . value . trim ( ) ; if ( username && email && password ) { const response = await fetch ( '/api/users' , { method : 'post' , body : JSON . stringify ( { username , email , github , password } ) , headers : { 'Content-Type' : 'application/json' } } ) ; if ( response . ok ) { console . log ( 'success' ) ; document . location . replace ( '/dashboard' ) ; } else { alert ( response . statusText ) ; } } }
create js to enable users to sign up
create js to enable users to sign up
// check the response status