Last active
November 28, 2018 10:52
-
-
Save Necmttn/35f3208eb024cdc08c8ce1c204ac9e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Button, Icon, message } from 'antd'; | |
import { navigateTo } from 'gatsby-link'; | |
import { Auth, Logger } from 'aws-amplify'; | |
import { LoginForm } from '../../Form' | |
const logger = new Logger('Auth:Login'); | |
class Login extends React.Component { | |
state = { status: 'idle' } | |
onSuccess(message) { | |
logger.debug('login success', message); | |
this.setState({ status: 'success' }); | |
navigateTo('/dashboard'); | |
} | |
onError(err) { | |
logger.error(err); | |
message.error(err.message) | |
this.setState({ status: 'error' }); | |
} | |
/** | |
* Log user in using cognito | |
*/ | |
onCognitoLogin = (values) => { | |
logger.debug('login start') | |
this.setState({ status: 'loading' }); | |
Auth.signIn(values.email, values.password) | |
.then((success) => this.onSuccess(success)) | |
.catch((err) => this.onError(err)); | |
} | |
render() { | |
return <LoginForm | |
onSubmit={this.onCognitoLogin} | |
centered="true" | |
status={this.state.status} | |
/> | |
} | |
} | |
export default Login; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment