Skip to content

Commit

Permalink
Signin.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lambrugeorge authored Feb 18, 2024
1 parent 1bf6c96 commit 08dc08d
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/components/Signin/Signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,30 @@ class Signin extends React.Component {
}

onSubmitSignIn = () => {
fetch('https://mybackend-dfd1.onrender.com/signin', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
email: this.state.signInEmail,
password: this.state.signInPassword
})
fetch('https://mybackend-dfd1.onrender.com/signin', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
email: this.state.signInEmail,
password: this.state.signInPassword
})
.then(response => response.json())
.then(user => {
if (user.id) {
this.props.loadUser(user)
this.props.onRouteChange('home');
} else {
this.setState({error: 'Authentication failed. Please check your email and password.'});
}
})
.catch(err => {
this.setState({error: 'There was an error signing in. Please try again later.'});
});
}

})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(user => {
if (user && user.id) {
this.props.loadUser(user);
this.props.onRouteChange('home');
} else {
throw new Error('User authentication failed');
}
})
.catch(error => console.error('Error:', error));
}
render() {
const { onRouteChange } = this.props;
return (
Expand Down

0 comments on commit 08dc08d

Please sign in to comment.