Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Api = {
- signUp(user) {
- console.log(Constant.default.apiUrl);
- return fetch(Constant.default.apiUrl + '/signup', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(user)
- })
- .then(response => response.json())
- .then(responseJson => {
- if (responseJson.success) {
- console.log(responseJson.userData);
- return responseJson.userData;
- } else {
- throw responseJson;
- }
- })
- .catch(err => {
- throw {
- // this just makes the error source obvious
- message: 'Error in sign up',
- error: err
- };
- });
- },
- login(user) {
- return fetch(Constant.default.apiUrl + '/login', {
- method: 'POST',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(user)
- })
- .then(response => response.json())
- .then(responseJson => {
- console.log("responsejson " + responseJson);
- console.log("laaaa");
- if (responseJson.success) {
- return responseJson.userData;
- } else {
- throw responseJson;
- }
- })
- .catch(err => {
- throw {
- // this just makes the error source obvious
- message: 'Error in login',
- error: err
- };
- });
- }
- };
- export default Api;
- function register() {
- if (this.state.password.length > 3 && this.state.password === this.state.confirmPassword) {
- var user = {
- firstName: this.props.firstName,
- lastName: this.props.lastName,
- emailAddress: this.state.emailAddress,
- password: this.state.password,
- };
- Api.signUp(user)
- .then((result) => {
- console.log("sign up result: " + JSON.stringify(result));
- return Api.login(user);
- })
- .then(result => {
- console.log("login result: " + JSON.stringify(result));
- })
- .catch(resultErr => console.log(resultErr));
- } else {
- this.setState({
- error: true,
- errorMessage: 'Veuillez remplir les champs correctement'
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement