Skip to content

Commit

Permalink
change onsubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
beiciliang committed Mar 6, 2023
1 parent 3e35274 commit efd6956
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions frontend-react-js/src/pages/SigninPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Link } from "react-router-dom";

// [TODO] Authenication
import Cookies from 'js-cookie'
import { Auth } from 'aws-amplify';

export default function SigninPage() {

Expand All @@ -13,15 +14,20 @@ export default function SigninPage() {
const [errors, setErrors] = React.useState('');

const onsubmit = async (event) => {
event.preventDefault();
setErrors('')
console.log('onsubmit')
if (Cookies.get('user.email') === email && Cookies.get('user.password') === password){
Cookies.set('user.logged_in', true)
event.preventDefault();
Auth.signIn(email, password)
.then(user => {
console.log('user',user)
localStorage.setItem("access_token", user.signInUserSession.accessToken.jwtToken)
window.location.href = "/"
} else {
setErrors("Email and password is incorrect or account doesn't exist")
}
})
.catch(error => {
if (error.code == 'UserNotConfirmedException') {
window.location.href = "/confirm"
}
setErrors(error.message)
});
return false
}

Expand Down

0 comments on commit efd6956

Please # to comment.