diff --git a/frontend-react-js/src/pages/SigninPage.js b/frontend-react-js/src/pages/SigninPage.js index 20de227..5b7c376 100644 --- a/frontend-react-js/src/pages/SigninPage.js +++ b/frontend-react-js/src/pages/SigninPage.js @@ -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() { @@ -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 }