Skip to content

Commit 251b5c4

Browse files
committed
Added connection configs. Changed saving dummy token to actually query that from server
1 parent a72f502 commit 251b5c4

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/config/connection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
// This is currently localhost at home. Android
3+
// requires the whole IP address instead of just
4+
// localhost
5+
SERVER_URL: 'http://192.168.1.101',
6+
};

app/screens/Register.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Icon from 'react-native-vector-icons/FontAwesome';
55
import connectAlert from './../components/Alert/connectAlert';
66
import deviceStorage from './../services/deviceStorage';
77
import Container from '../components/Container';
8+
import connection from './../config/connection';
89

910
class Register extends Component {
1011
constructor(props) {
@@ -19,7 +20,7 @@ class Register extends Component {
1920
}
2021

2122
// Fix eslint/babel issue and transform this to async await
22-
registerUser = () => {
23+
registerUser = async () => {
2324
const { email, password, confirmPassword } = this.state;
2425

2526
if (email.length === 0) {
@@ -36,8 +37,27 @@ class Register extends Component {
3637
return this.props.alertWithType('error', 'Error', 'Email not valid');
3738
}
3839

39-
deviceStorage.saveItem('id_token', 'jwttoken123');
40-
this.props.navigation.navigate('App');
40+
try {
41+
const URL = `${connection.SERVER_URL}:4500/user/signup`;
42+
console.log(URL);
43+
const response = await fetch(URL, {
44+
method: 'POST',
45+
headers: {
46+
Accept: 'application/json',
47+
'Content-Type': 'application/json',
48+
},
49+
body: JSON.stringify({
50+
email,
51+
password,
52+
}),
53+
});
54+
console.log(response);
55+
// deviceStorage.saveItem('id_token', response.data.jwt);
56+
// this.props.navigation.navigate('App');6
57+
} catch (error) {
58+
console.log(error);
59+
return this.props.alertWithType('error', 'Error', `Something went wrong: ${error}`);
60+
}
4161
}
4262
render() {
4363
return (

0 commit comments

Comments
 (0)