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 b9a68aa commit 0b7bafa
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/components/Signin/Signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,32 @@ class Signin extends React.Component {
this.setState({signInPassword: event.target.value})
}

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
})
})
.then(response => {
onSubmitSignIn = async () => {
try {
const response = await 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
})
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(user => {

const user = await response.json();

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));
} catch (error) {
console.error('Error:', error);
}
}
render() {
const { onRouteChange } = this.props;
Expand Down

0 comments on commit 0b7bafa

Please sign in to comment.