This repository has been archived by the owner on Feb 24, 2018. It is now read-only.
/
main.jsx
75 lines (66 loc) · 1.82 KB
/
main.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {Config, CognitoIdentityCredentials} from "aws-sdk";
import {
CognitoUserPool,
CognitoUserAttribute
} from "amazon-cognito-identity-js";
import React from "react";
import ReactDOM from "react-dom";
import appConfig from "./config";
Config.region = appConfig.region;
Config.credentials = new CognitoIdentityCredentials({
IdentityPoolId: appConfig.IdentityPoolId
});
const userPool = new CognitoUserPool({
UserPoolId: appConfig.UserPoolId,
ClientId: appConfig.ClientId,
});
class SignUpForm extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
};
}
handleEmailChange(e) {
this.setState({email: e.target.value});
}
handlePasswordChange(e) {
this.setState({password: e.target.value});
}
handleSubmit(e) {
e.preventDefault();
const email = this.state.email.trim();
const password = this.state.password.trim();
const attributeList = [
new CognitoUserAttribute({
Name: 'email',
Value: email,
})
];
userPool.signUp(email, password, attributeList, null, (err, result) => {
if (err) {
console.log(err);
return;
}
console.log('user name is ' + result.user.getUsername());
console.log('call result: ' + result);
});
}
render() {
return (
<form onSubmit={this.handleSubmit.bind(this)}>
<input type="text"
value={this.state.email}
placeholder="Email"
onChange={this.handleEmailChange.bind(this)}/>
<input type="password"
value={this.state.password}
placeholder="Password"
onChange={this.handlePasswordChange.bind(this)}/>
<input type="submit"/>
</form>
);
}
}
ReactDOM.render(<SignUpForm />, document.getElementById('app'));