Skip to content

Commit 9ebd4fd

Browse files
committed
Home
1 parent 2df3cf3 commit 9ebd4fd

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

App/auth/Auth.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function getToken(values) {
4848
USER_TOKEN = await responseData.token
4949
USER_REFRESH_TOKEN = await responseData.refresh_token
5050

51-
onSignIn()
51+
await onSignIn()
5252
return 200
5353
}
5454
else if (responseData.code === 401) {
@@ -67,9 +67,9 @@ export async function getToken(values) {
6767
}
6868

6969
export const onSignIn = async () => {
70-
AsyncStorage.setItem("user_id", JSON.stringify(USER_ID))
71-
AsyncStorage.setItem("token", USER_TOKEN)
72-
AsyncStorage.setItem("refresh_token", USER_REFRESH_TOKEN)
70+
await AsyncStorage.setItem("user_id", JSON.stringify(USER_ID))
71+
await AsyncStorage.setItem("token", USER_TOKEN)
72+
await AsyncStorage.setItem("refresh_token", USER_REFRESH_TOKEN)
7373
};
7474

7575
export async function getUserId() {

App/view/Home.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as TaskManager from 'expo-task-manager';
99
import { Stopwatch } from 'react-native-stopwatch-timer';
1010
import SafeAreaView from 'react-native-safe-area-view';
1111
import * as geolib from 'geolib';
12+
import config from "../config/config";
13+
import {onSignIn} from "../auth/Auth";
1214

1315
const STORAGE_KEY_COORDINATES = 'COORDINATES';
1416
const STORAGE_KEY_STATS = 'STATS';
@@ -154,6 +156,36 @@ export default class Home extends Component {
154156
// // console.log(uri);
155157
// });
156158
dataStats[0].coordinates = dataCoordinates;
159+
const getUserToken = await Home.getData("token");
160+
console.log(getUserToken);
161+
fetch(``+config.API_URL+`/api/courses`, {
162+
163+
method: 'POST',
164+
headers: {
165+
Accept: 'application/json',
166+
'Content-Type': 'application/json',
167+
'Authorization': 'Bearer '+getUserToken
168+
},
169+
body: JSON.stringify({
170+
"distance": 0,
171+
"avgSpeed": 0,
172+
"maxSpeed": 0,
173+
"time":'15:26:00',
174+
"createdAt": "2020-03-29T15:26:33.386Z",
175+
"coordinates": [
176+
"10"
177+
],
178+
"user": "/api/users/1"
179+
})
180+
})
181+
.then(async resp => {
182+
console.log(resp);
183+
return resp.json()
184+
}).then(async responseData => {
185+
console.log(responseData);
186+
return 200
187+
})
188+
157189

158190
this.setState({started: false,startTime: 0,markers :markers,routeCoordinates: dataCoordinates});
159191

0 commit comments

Comments
 (0)