src/components/register/Register.js
/**
     * HTTP POST request is sent to the backend.
     * If the request is successful, a new user is returned to the front-end and its token is stored in the localStorage.
     */
HTTP POST request is sent to the backend.
If the request is successful, a new user is returned to the front-end and its token is stored in the localStorage.
HTTP POST request is sent to the backend . If the request is successful a new user is returned to the front - end and its token is stored in the localStorage .
register() {
        fetch(`${getDomain()}/users`, {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json"
            },
            body: JSON.stringify({
                username: this.state.username,
                password: this.state.password
            })
        })
            .then(response =>{
            if(response.status === 409) {
                alert("This Username is already taken. Try another one.");
            }
            else{
                alert("Your account has been created");
                this.props.history.push('login');
            }
        })
            .catch(err => {
                if (err.message.match(/Failed to fetch/)) {
                    alert("The server cannot be reached. Did you start it?");
                } else {
                    alert(`Something went wrong during the registration: ${err.message}`);
                }
            });
    }
register ( ) { fetch ( ` ${ getDomain ( ) } ` , { method : "POST" , headers : { "Content-Type" : "application/json" , "Accept" : "application/json" } , body : JSON . stringify ( { username : this . state . username , password : this . state . password } ) } ) . then ( response => { if ( response . status === 409 ) { alert ( "This Username is already taken. Try another one." ) ; } else { alert ( "Your account has been created" ) ; this . props . history . push ( 'login' ) ; } } ) . catch ( err => { if ( err . message . match ( / Failed to fetch / ) ) { alert ( "The server cannot be reached. Did you start it?" ) ; } else { alert ( ` ${ err . message } ` ) ; } } ) ; }
HTTP POST request is sent to the backend.
HTTP POST request is sent to the backend .
//does not need any token for auth